Click here to Skip to main content
16,004,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how to retrieve particular column data to label from ssql to asp.net label
thanks in adv and happy ugadi to all my friends at this forum.. happy to be in this form for the great support i learnt and learing things
Posted

Execute your query:select <column-name> from <table-name>;

now, data-row read() while last-row and append the string in stringbuilder .

now label1.Text=stringbuilder.ToString();
 
Share this answer
 
Hi, try like this:

C#
protected void btnTest_Click(object sender, EventArgs e)
   {

String ConnStr = "Data Source=ServerName;Initial Catalog=DBNamae;User ID=UserName;Password='password';";
        String SQL = "SELECT ID, FirstName FROM Employee "
           + "WHERE ID IS NOT NULL";
        SqlDataAdapter TitlesAdpt = new SqlDataAdapter(SQL, ConnStr);
        DataSet Titles = new DataSet();
        // No need to open or close the connection
        //   since the SqlDataAdapter will do this automatically.
        TitlesAdpt.Fill(Titles);
YourLabel.Text=Titles.Table[0].Rows[0]["FirstName"].ToString();
}


Here assuming that the table is Employee and the FirstName will show in your lable.
Best of luck
 
Share this answer
 
SQL
SELECT <column_name> FROM <table_name></table_name></column_name>


Now in the front part you can do....
connect to data server..

C#
SqlConnection Con = new SqlConnection(Connstr);
string str = "SELECT <column_name> FROM <table_name> <where condition="">";
SqlCommand cmd = SqlCommand(str, Con);

SqlDataAdapter Adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();

Adapter.Fill(dt);

lbl.text = dt.Rows[0].ItemArray[0].ToString();
</where></table_name></column_name>


Now you can find selected column data in the label....
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900