Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8581

How to insert Data to MS access using C#

$
0
0

I created a database in ms access, in the database I have a table with two columns, fist column is Name with Text data type, and the other column is Date with Date/time data type. and I want to insert values in the table, but it give this error for the month calendar

 

Data type mismatch in criteria expression.

 

string sqlQuery = "INSERT INTO register (`Name`,`Date`) values (?,?)";

   using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\DB.accdb"))

   using (OleDbCommand cmd = new OleDbCommand(sqlQuery, conn))

  {

 

  conn.Open();

  cmd.Parameters.AddWithValue("@Name", this.textBox1.Text);

  cmd.Parameters.AddWithValue("@Date", this.monthCalendar1.Text);

  cmd.ExecuteNonQuery();

  }


Viewing all articles
Browse latest Browse all 8581

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>