1
Answer

Displaying Data

Photo of Stark

Stark

12y
996
1
hello everyone,
i am really very new to asp.net. please help me out here. i want to retrieve data from the sql server. i have a column in the table that contains the same value as the user login name,so when retrieving data i want to use the login name how do i do that?pliz help me.

thanks in advance...

Answers (1)

0
Photo of Sandeep Singh Shekhawat
NA 22.4k 12m 12y
1. imports namesapce in class

using System.Data.SqlClient;

2. create a function in that class which retrun sqlConnection
public static SqlConnection Connection()
         {
            string connectionString = "Data Source=sandeepss-PC;database=Development;user=sa;password=knowdev";
            SqlConnection con = new SqlConnection();
            con.ConnectionString = connectionString;
            return con;
        }

3 create a function which return all login names in a data Table
 public static DataTable getUserLogin()
         {
             DataTable dt = new DataTable();
             SqlConnection con = Connection();
             SqlCommand cmd = new SqlCommand();
             cmd.CommandText = "select userLogin from tbl_login";
             cmd.Connection = con;
             con.Open();
             SqlDataReader reader = cmd.ExecuteReader();
             dt.Load(reader);
             return dt;
         }