droiddeve says:
private
void
Fillsections(
int
ClassId)
{
SqlConnection con =
new
SqlConnection();
con =
new
SqlConnection(connectionString);
SqlCommand cmd =
new
SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"SELECT Section_Id, SectionName FROM Tbl_Sections WHERE ClassId =@ClassId"
;
cmd.Parameters.AddWithValue(
"@ClassId"
, ClassId);
DataSet objDs =
new
DataSet();
SqlDataAdapter dAdapter =
new
SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
if
(objDs.Tables[0].Rows.Count > 0)
{
combostudesection.ValueMember =
"Section_Id"
;
combostudesection.DisplayMember =
"SectionName"
;
combostudesection.DataSource = objDs.Tables[0];
}
}
replace above code with below
private void Fillsections(int ClassId)
{
SqlConnection con = new SqlConnection();
con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT Section_Id, SectionName FROM Tbl_Sections WHERE ClassId =@ClassId";
cmd.Parameters.AddWithValue("@ClassId", ClassId);
DataTable objDs = new DataTable();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
if (objDs.Rows.Count > 0)
{
combostudesection.ValueMember = "Section_Id";
combostudesection.DisplayMember = "SectionName";
combostudesection.DataSource = objDs;
DataRow dr = objDs.NewRow();
dr["Section_Id"] = "0";
dr["SectionName"] = "Select";
objDs.Rows.InsertAt(d, 0);
}
}