Vaibhav Solaskar

Vaibhav Solaskar

  • NA
  • 30
  • 17.2k

there is value is no incremented in the text box

Mar 21 2016 4:57 AM
This is my code for generating roll no in pattern of
txtrollno = dropdownlist1.selectedvalue+ "00" + 1
i.e in dropdown list we can select a course id and its is start of roll no means my roll no is 306001 i.e my course id is 306 
and there is no increment is done 
 
 
 
con.Open();
a = "select count(*),Course_ID from Student_Master where Course_ID="+DropDownList3.SelectedValue +"group by Course_ID";
cmd = new SqlCommand(a,con);
try
{
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
str1=rdr.GetInt32(0).ToString();
cnt = rdr.GetInt32(0);
txtRollNo.Text = str1;
}
rdr.Close();
}
catch(Exception ex)
{
con.Close();
throw ex;
}
str1=DropDownList3.SelectedValue;
if (cnt > 0)
{
if (cnt <= 9)
newid = str1 + "00" + cnt;
else
newid = str1 + "0" + cnt;
}
else
{//--- if no records in database
str1 = DropDownList3.SelectedValue;
newid = str1 + "00" + 1;
}
if (newid != "")
txtRollNo.Text = newid;

Answers (3)