if this happening i want to move on next row of table and if row is there that row's value should display
public partial class WebForm9 : System.Web.UI.Page { SqlCommand cmd = new SqlCommand(); DataTable dt = new DataTable(); DataRow drr; public string ans_tea; public string ans_stu; SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=swatidb;Integrated Security=True;Pooling=False"); static int i = 0; public void Page_Load(object sender, EventArgs e) { con.Open(); string tea_id = TextBox2.Text; string s1 = "select student_id from Student where user_name='" + Session["sid"] + "'"; SqlCommand cmd = new SqlCommand(s1, con); SqlDataReader dr; dr = cmd.ExecuteReader(); if (dr.Read()) { Label4.Text = dr[0].ToString(); dr.Close(); } } public void Button2_Click(object sender, System.EventArgs e) { string tea_id = TextBox2.Text; cmd = new SqlCommand("SELECT * from Question WHERE Teacher_id=@tea_id", con); cmd.Parameters.AddWithValue("@tea_id", tea_id); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt);//at this line getting Exception so how can i avoid getting this Exception drr = dt.Rows[i]; if (i == (dt.Rows.Count - 1)) { Response.Write("Last record !"); } else { i++; } Label3.Text = Convert.ToString(drr[0]);//for displaying question_id Label2.Text = Convert.ToString(drr[2]);//for displaying question con.Close(); }
if (i >= dt.Rows.Count)) { Response.Write("There are no record !"); con.Close(); return; } drr = dt.Rows[i]; //... your old code!
static int i = 0;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)