5
Answers

Display the database column value in the label

sita k

sita k

12y
20.8k
1
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.
Answers (5)
2
gagan sharma

gagan sharma

NA 7 0 10y
SqlConnection con = new SqlConnection();
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");
}
0
Muhammad Ishaq

Muhammad Ishaq

NA 5 569 9y
Thanks
0
sita k

sita k

NA 43 53k 12y
Hi, I wanted to get the sequence value in to the text box while inserting the values in to the database. I have a customer table while inserting the details of the customer through client side i need to display the seq id of the cusomter after submitting the details.
0
Gohil Jayendrasinh

Gohil Jayendrasinh

NA 5.1k 3.7m 12y
Hi
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);
}

}
}

0
Dorababu Meka

Dorababu Meka

232 8.3k 1.7m 12y
Firstly establish a connection

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();