I am trying to insert values entered by a user on a Winform into the following Access table:
The C# code is:
OleDbCommand oleCmd = new OleDbCommand("INSERT INTO Projects (projectTitle,partyID,receiveDate,dueDate, projectTypeID, pages, "+
"lines, words, prepay, cost, settled,projectComment)"
+ " VALUES (@projectTitle,@partyID,@receiveDate,@dueDate,@projectTypeID,@pages, @lines, @words, @prepay, @cost, @settled, @projectComment)", conn);
PersianCalendar p=new PersianCalendar();
DateTime thisDate=DateTime.Now;
oleCmd.Parameters.Add("@projectTitle", OleDbType.VarChar).Value = txtProjectTitle.Text;
oleCmd.Parameters.Add("@partyID", OleDbType.Numeric).Value = Convert.ToInt32(comboProjectType.SelectedValue.ToString());
oleCmd.Parameters.AddWithValue("@receiveDate", string.Format( "{0}, {1}/{2}/{3} {4}:{5}:{6}",
p.GetDayOfWeek(thisDate), p.GetYear(thisDate),p.GetMonth(thisDate),p.GetDayOfMonth(thisDate), p.GetHour(thisDate),p.GetMinute(thisDate),p.GetSecond(thisDate))) ;
oleCmd.Parameters.Add("@dueDate", OleDbType.VarChar).Value = comboDay.Text + "/" + comboMonth.Text + "/" + comboYear.Text;
oleCmd.Parameters.Add("@projectTypeID", OleDbType.Numeric).Value = Convert.ToInt32(comboContractParty.SelectedValue.ToString());
oleCmd.Parameters.AddWithValue("@pages", Convert.ToInt32(txtPages.Text));
oleCmd.Parameters.AddWithValue("@lines", Convert.ToInt32(txtLines.Text));
oleCmd.Parameters.AddWithValue("@words", Convert.ToInt32(txtWords.Text));
oleCmd.Parameters.AddWithValue("@cost", Convert.ToDouble(txtWholeProjCost.Text));
oleCmd.Parameters.AddWithValue("@prepay", Convert.ToDouble(txtPrePay.Text));
oleCmd.Parameters.AddWithValue("@settled", chkSettled.CheckState);
oleCmd.Parameters.Add("@projectComment", OleDbType.VarChar).Value = txtComment.Text.ToString();
try
{
conn.Open();
oleCmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
The exception says:
Data type mismatch in criteria expression.
I rechecked the types, but don't know where the error is raised from.
thisDate? - Gord Thompson... VALUES (@projectTitle,@partyID,Date(),@dueDate, ...and comment out the statement that creates the @receiveDate parameter? - Gord Thompson