I have databse in access 2007. my date datatype is Date/Time. I have made function to insert values to database.
But it is showingd syntax error(missing operation)..." for insering date.
Please help me how should i do i have tried hash in front of date and tried to save with
parameters.
My function is
public void purchaseProduct(string productname, string challan_no, DateTime challan_date, string bill_no, DateTime bill_date, string Customer)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
OleDbCommand insert = new OleDbCommand("INSERT INTO [PRODUCT_DETAILS]([PRODUCT_NAME],[CHALLAN_NO],[CHALLAN_DATE],[BILL_NO],[BILL_DATE],[CUST_NAME])VALUES('"+productname+"','"+challan_no+"','#'+challan_date+'#','"+bill_no+"','#'+bill_date+'#','"+Customer+"')", con);
insert.ExecuteNonQuery();
MessageBox.Show("Your data has been saved.");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
here how I am calling this function and I have used datetime picker.
add.purchaseProduct(txtproductname.Text.ToUpper(), txtchallan_no.Text.ToUpper(), txtchallan_date.Value.Date, txtbill_no.Text.ToUpper(), txtbill_date.Value.Date, txtCustomer.Text.ToUpper());
Rimmi90
0
Newbie Poster
Recommended Answers
Jump to PostThe Access DateTime format might be different to the C#.NET DateTime format, this is the case with SQL Server. try to research both C#.NET and Access DateTime format and try to figure out how to convert the C# DateTime so that it can be stored in the DB.
Jump to PostOr use parameterized queries and you don't have to worry about formats.
All 5 Replies
ChrisHunter
152
Posting Whiz in Training
Featured Poster
Momerath
1,327
Nearly a Senior Poster
Featured Poster
Rimmi90
0
Newbie Poster
kvprajapati
1,826
Posting Genius
Team Colleague
Rimmi90
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.