Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET SQL ADO.NET
My Emp table is stored in sql server which consist of columns ID,Name,Age & adress.
I want to Display the name of employee in textboxes whose age is 25.
how shoul I connect the database for such a task.
Posted 5-Jan-13 2:19am
Comments
Reza Alipour Fard at 5-Jan-13 15:30pm
   
I think you is popular. Therefore I present a class for management connecting to sql and get data.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This looks like a very basic question. If you are not familiar with ADO.net go through these CP articles.
Using ADO.NET for beginners[^]
Database Manipulation with ADO.NET for beginners[^]
A Beginner's Tutorial for Understanding ADO.NET[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi
 
You can Use from bellow method for manage Database:
 
public class DBManagement
{
    public SqlConnection OpenConnection()
    {
        string connectionString = "Data Source = [ServerName]; Initial Catalog = [DatabaseName]; User ID = [SqlUserName]; Password = [SqlUserPassword]";
 
        SqlConnection connection = null;
 
        try
        {
            connection = new SqlConnection(connectionString);
            connection.Open();
        }
        catch
        {
            Console.WriteLine("DataBase is not reachable....");
        }
 
        return connection;
 
    }
 
    public DataTable Execute(string queryString)
    {
        SqlConnection connection = OpenConnection();
 
        SqlCommand query = new SqlCommand(queryString, connection);
 
        DataTable resultTable = new DataTable();
 
        SqlDataAdapter adopter = new SqlDataAdapter(query);
 
        adopter.Fill(resultTable);
 
        connection.Close();
 
        return resultTable;
    }
}
 
 
Now you can create instance from DBManagement and call execute method by send bellow string az query:
 
string query = "Select Name From YourTableName Where Age = 25";
DBManagement manage = new DBManagement();
 
DataTable result = manage.Execute(query);
 
I hope it's helpful.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 359
1 Sergey Alexandrovich Kryukov 355
2 CPallini 335
3 BillWoodruff 324
4 OriginalGriff 237
0 OriginalGriff 5,050
1 CPallini 4,225
2 Sergey Alexandrovich Kryukov 3,639
3 George Jonsson 2,911
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100