I have a table that contains information like(examId, examActive) and I want to display a particular examId in a textbox. I am new
in ASP.Net and SQL. Please Help me. Here is my code, what
else I have to do.
vcon.Open();
SqlDataAdapter da = new SqlDataAdapter("select examId from ExamConfig where examActive='1'", vcon);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
da.Fill(ds);
txtExamId.Text = dt.Rows[1]["examId"].ToString();
vcon.Close();
Loading
Ravi ShekharPosted Jul 17, 2013, 5:47 AM
SqlDataAdapter da = new SqlDataAdapter("select examId from ExamConfig where examActive='1'", vcon);
DataTable dt = new DataTable();
da.Fill(dt);
txtExamId.Text = dt.Rows[0]["examId"].ToString();
==============================================
Now, If your query returns multiple row then you have to take any data container like datagridview, datalist etc. and do coding like below...
SqlDataAdapter da = new SqlDataAdapter("select examId from ExamConfig where examActive='1'", vcon);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
datagridview1.datasource=dt;
datagridview1.databind();
}
Regards,
ravi
mark it as answer if it helped you
Kunal VaishyaPosted Jul 17, 2013, 5:23 AM
Sanjeeb LenkaPosted Jul 17, 2013, 4:56 AM
SqlDataAdapter da = new SqlDataAdapter("select examId from ExamConfig where examActive='1'", vcon);
DataSet ds = new DataSet();
da.Fill(ds);
txtExamId.Text =ds.Tables[0].Rows[0][0].ToString();
Riyaz AkhtarPosted Jul 17, 2013, 4:53 AM
txtExamId.Text = ds.Tables[0].Rows[0]["examId"].ToString();
Sayed HassanPosted Jul 17, 2013, 4:49 AM
Anurag SarkarPosted Jul 17, 2013, 4:47 AM
SqlConnection con = new SqlConnection("Data Source=hightech;Initial Catalog=session; User ID=sa; password=sa");
String str = "select ename,job from emp";
SqlCommand cmd = new SqlCommand(str, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
TextBox1.Text = dr["ename"].ToString();
Label1.Text = dr["job"].ToString();
}
con.Close();
Thanx
Riyaz AkhtarPosted Jul 17, 2013, 4:42 AM