Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HTML
con.Open();
       SqlCommand cmd = new SqlCommand("insert into reg values('" + lbl_id.Text + "','" + lbl_dat.Text + "','" + txt_name.Text + "','" + txt_pwd.Text + "','" + txt_num.Text + "','" + txt_city.Text + "','" + txt_email.Text + "')", con);
       cmd.ExecuteNonQuery();
       con.Close();
       MsgBox.Show("registered successfully");
       Response.Redirect("login.aspx");


The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.


i want this type of code.
Posted
Comments
Thomas ktg 20-Sep-13 6:55am    
what is the database you are using?

Hey the best way to see what the issue is here if insert a breakpoint at cmd.ExecuteNonQuery() and see what the value of lbl_dat.Text is at that point. I suggest as the error says its not a valid datetime...

Also on a seperate note you are leaving yourself open to sql injection attacks....

Hope that helps...
 
Share this answer
 
v2
In database Store the value in 'MM/dd/yyyy' this format only allow the database so pass the the date in valid database format don't Pass 'dd/MM/yyyy'
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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