i have table like
sno name address gender empcode salary
1 shashi hyd male a01 5000
2 raju xxx male a09 4000
3
i have aspx page like
four texboxs
i want read only empcode=a09 only
o/p like
textbox1 value= raju
textbox2 value=xxx
textbox3 value=male
textbox4 value=4000
Anupam SinghPosted May 15, 2014, 5:38 AM
change select statement to string selectSql = "select * from Employee where Empcode='a09'";
it should work.
Hussain AhmedPosted May 15, 2014, 5:14 AM
SqlDataAdapter da = new SqlDataAdapter("select * from table where empcode='" + TextBox1.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count >= 0)
{
TextBox2.Text = ds.Tables[0].Rows[0]["name"].ToString();
TextBox3.Text = ds.Tables[0].Rows[0]["address"].ToString();
TextBox4.Text = ds.Tables[0].Rows[0]["gender"].ToString();
TextBox5.Text = ds.Tables[0].Rows[0]["salary"].ToString();
}
Umesh KumarPosted May 15, 2014, 5:08 AM
Write a query to get the data to a datatable
if(dt.row.count>0)
{
textbox1 .Text=dt.Rows[0].["name"];
}
Abhay ShankerPosted May 15, 2014, 5:08 AM
Try as below
string conString = @"Data Source=localhost;Initial Catalog=dbname;Integrated Security=True";
SqlConnection con = new SqlConnection(conString);
string selectSql = "select * from Employee where Empcode=a09";
SqlCommand com = new SqlCommand(selectSql, con);
try
{
con.Open();
using (SqlDataReader read = cmd.ExecuteReader())
{
while(reader.Read())
{
TextBox1.Text = (read["name"].ToString());
TextBox2.Text = (read["address"].ToString());
TextBox3.Text = (read["gender"].ToString());
TextBox4.Text = (read["Salary"].ToString());
}
}
}
finally
{
con.Close();
}