Hi,
public DataTable getCourseById(int courseID)
{
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using(SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("select * from course where id=@courseID", con);
con.Open();
cmd.Parameters.AddWithValue("@courseID",courseID);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
protected void ddlCourse_SelectedIndexChanged(object sender, EventArgs e)
{
int id = Convert.ToInt32(ddlCourse.SelectedValue);
DataTable dt = new DataTable();
dt = course.getCourseById(id);
txtLabel.Text = dt.Rows[0][1].ToString();
txthours.Text = Convert.ToInt32(dt.Rows[0][2]).ToString();
txtDesc.Text = dt.Rows[0][3].ToString();
}
As soon as select the course in dropdownlist it is giving me the error saying that there is no row at position 0
Thanks