Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Database as follows

studentid crbillno DOM

133 124290 20-01-2014


In run mode screen as follows

Batch Date 28-06-2014


i have one button called Submit.

When i click the submit i want to validate dropdownlist date must be less than DOB date(DOM).


for that my code as follows

DateTime coursedate;
     coursedate = Convert.ToDateTime(DdlBthDates.SelectedItem.Text.ToString());
     Sql = "select DOM from course where stud_id = '" + Session["stud_id"] + "' and CR_BILL_NO  =  '" + Session["cr_bill_no"] + "'";
     coursedr = drr.ExecRdr(Sql);
     if (coursedate < Convert.ToDateTime(coursedr[0].ToString().Trim()))
     {
         Label23.Text = "date must be ";
         return;
     }
     coursedr.Close();


when i run the code shows error as follows

Invalid attempt to read no data present.

Regards,
Narasiman P.
Posted
Updated 8-Apr-14 3:27am
v2

1 solution

0) I expect that ExecRdr is returning a DataReader, but you do not Read from it -- you'll need to do that.
1) Mightn't ExecuteScalar be a better way to get the one value you want?
2) Don't call ToString() on the value, just cast it to DateTime
3) Please use a parameterized query rather than concatenation.
 
Share this answer
 
Comments
Maciej Los 8-Apr-14 10:34am    
The most shortest tutorial i've ever seen ;)
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900