Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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
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
Please Sign up or sign in to vote.

Solution 1

This looks like a very basic question. If you are not familiar with 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[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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;
            connection = new SqlConnection(connectionString);
            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);
        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.

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