Hi,
I am new to ASP.NET.I wanted to know how can i get the the database column value from database to the label box which i wanted to be displayed after inserting the values.
Sita.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
gagan sharma9 reputationPosted Jul 23, 2014, 12:18 AM EDT
con.ConnectionString = ConfigurationManager.ConnectionStrings["CN"].ConnectionString;
string query = "select * from Product";
SqlDataAdapter adp = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
lblClient.Enabled = true;
lblClient1.Enabled = true;
lblClient2.Enabled = true;
lblClient3.Enabled = true;
lblClient.Text = ds.Tables[0].Rows[0].Field("P_Name");
lblClient1.Text = ds.Tables[0].Rows[1].Field("P_Name");
lblClient2.Text = ds.Tables[0].Rows[2].Field("P_Name");
lblClient3.Text = ds.Tables[0].Rows[3].Field("P_Name");
}
Dorababu MekaRank #457 · 5.5K reputationPosted Feb 17, 2013, 8:12 PM EST
SqlConnection con=new SqlConnection("urconnectionstring");
SqlCommand cmd=new SqlCommand("select query to retrieve the label value",con);
con.open();
SqlDataAdapter da=new SqlDataAdapter();
da.SelectCommand=cmd;
Dataset ds=new DataSet();
da.Fill(ds);
Label1.Text=ds.Tables[0].Rows[0]["Coulmnname"].ToString();
Gohil JayendrasinhRank #490 · 5K reputationPosted Feb 17, 2013, 8:12 PM EST
DataTable dt = new DataTable();
-- fill datatable
if (dt.Columns.Count > 0)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
if (dt.Columns[i].ColumnName != null)
{
string columnname = Convert.ToString(dt.Columns[i].ColumnName);
}
}
}
sita k41 reputationPosted Mar 6, 2013, 11:03 AM EST
Muhammad Ishaq4 reputationPosted May 31, 2015, 2:43 AM EDT