darma teja

darma teja

  • NA
  • 496
  • 336.4k

Problem in exporting masked text box date to databse columns

May 22 2012 6:49 AM
Hi,

I am loading the user entered data from the form to sql database. 

Here is my code:

SqlConnection con = new SqlConnection("bla bla");
con.Open();
string insertsql = "insert into John (date1, date2, date3)" + "values ('"  " "', '" + maskedTextBox1.Text + "', '" + maskedTextBox2.Text + "', '" + maskedTextBox3.Text +"');";
SqlCommand insertcmd = new SqlCommand(insertsql, con);
insertcmd.ExecuteNonQuery(); 
con.close();

All masked textboxes are in date format only.

My question is:

If i dont enter the date on the form in masked textboxes, i am getting error.

How can i enter null values in database.

Darma



Answers (5)