Skip to content

Displaying Data

Stark

Asked Oct 29, 2012, 8:16 PM EDT1 answer
Share
LinkedInX
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...

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Sandeep Singh Shekhawat
    0
    1. imports namesapce in class

    using System.Data.SqlClient;

    2. create a function in that class which retrun sqlConnection
    C#
    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
    Java
     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;
             }

    0