Reputation: 19
When I press the register button, a MessageBox will show up and then this happens:
No mapping exists from object type System.Windows.Forms.DateTimePicker to a known managed provider native type.
How do I fix this?
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = @"Data Source=MYCOMPUTER-PC\SQLEXPRESS;Database=COMPPROG;User
Id=user;Password=password";
SqlCommand scmd = new SqlCommand("SELECT COUNT (*) as cnt from USERACCOUNT", sqlcon);
SqlCommand cmd = sqlcon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO USERACCOUNT
(FName,MName,Sname,TxtBirth,comboGender,textBox8,textBox1,textBox2)
VALUES(@FName,@MName,@Sname,@TxtBirth,@comboGender,@textBox8,@textBox1,@textBox2)";
cmd.Parameters.AddWithValue("@FName", FName.Text);
cmd.Parameters.AddWithValue("@MName", MName.Text);
cmd.Parameters.AddWithValue("@Sname", Sname.Text);
cmd.Parameters.AddWithValue("@TxtBirth", TxtBirth);
cmd.Parameters.AddWithValue("@textBox8", textBox8.Text);
cmd.Parameters.AddWithValue("@textBox1", textBox1.Text);
cmd.Parameters.AddWithValue("@textBox2", textBox2.Text);
cmd.Parameters.AddWithValue("@comboGender", comboGender);
sqlcon.Open();
MessageBox.Show("Record added sucessfully!", "Registration Success!");
cmd.ExecuteNonQuery();
sqlcon.Close();
Upvotes: 1
Views: 108
Reputation: 1149
Like @gunr2171 said in comments problem is from this line so change it like this :
cmd.Parameters.AddWithValue("@TxtBirth", TxtBirth.Value);
This is value of TxtBirth for your query.
Edit :
DatePicker
itself and it can not be done.Upvotes: 1