Click here to Skip to main content
13,248,927 members (44,750 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 3:19am
Reza Alipour Fard 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2017
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