narasiman rao

narasiman rao

  • NA
  • 519
  • 768.5k

Displaying the database record using datatbale in c#

Dec 22 2015 10:25 PM
 
  i am displaying the database record using datatable
In LatestNewsMaster table record as follows

id Subject Link Active
1 Defect Mail defectmail.aspx A
2 Accounts Fee accountsfee.aspx A
3 Latestenews page Latestnews.aspx A

My code as follows

string constr = ConfigurationManager.ConnectionStrings["Reception2_DB"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select Link from LatestNewsMaster where active <> 'd'"))
{
cmd.Connection = con;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
sda.Fill(dt);
label1.Text = dt.Rows[0][0].ToString().Trim();
return dt;
}
}
}

But when i run in label dsiplaying only firt recrod defectmail.aspx in the label1. not displaying all the three link records from the database.

from my above code what is the mistake i made. 

Answers (2)