i have a problem here with my code, it happens that if i save an ordinary text or number, it is working, but when i try to save time and dates, an error will occur and saying

My Error

Syntax error in INSERT INTO statement.

here is my code.

//DECLARATIONS3
        OleDbDataAdapter da2;
        OleDbCommandBuilder cb2;
        DataTable dt2 = new DataTable();

//My Syntax

 private void btnTotalOrder_Click(object sender, EventArgs e)
        {
            string time2;

           for (int i = 0; i < listView2.Items.Count; i++)
            {
                ListViewItem lv = listView2.Items[i];
                DataRow drNrow = dt2.NewRow();
                drNrow[1] = lv.SubItems[0].Text;
                drNrow[2] = lv.SubItems[1].Text;
                drNrow[3] = lv.SubItems[2].Text;
                drNrow[4] = lblreceiptno.Text;
                drNrow[5] = txtcname.Text;
                drNrow[6] = time2.ToString();
                dt2.Rows.Add(drNrow);
                [COLOR="red"]da2.Update(dt2);[/COLOR]
                dt2.Rows.Clear();
                da2.Fill(dt2);
}
}

It points on my DataAdapter.Update(DataTable);

Recommended Answers

All 2 Replies

Please use code tags when posting code on daniweb:

[code]

....code here....

[/code]

That code uses an unitialized value and it won't compile so that can't be the code you are using. Please post your full unit in code tags so we can review. Even so calling time2.ToString() on an unitialized string would throw a null reference exception.

//My Error
Syntax error in INSERT INTO statement.

here is my code.

//DECLARATIONS3
OleDbConnection con;
OleDbDataAdapter da2;
OleDbCommandBuilder cb2;
DataTable dt2 = new DataTable();

//My Syntax

        //RESTAURANT LOAD EVENT
        private void Restaurant_Load(object sender, EventArgs e)
        {
            //Time
            string time1;
            time1 = DateTime.Now.ToShortTimeString();

            lbldate.Text = DateTime.Today.ToShortDateString();

            con = new OleDbConnection();
            con.ConnectionString =                                      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\VillaOcampoResort.mdb";
            con.Open();

            da2 = new OleDbDataAdapter("Select * from tblRestoOrder",con);
            cb2 = new OleDbCommandBuilder(da2);
            da2.Fill(dt2);
}


private void btnTotalOrder_Click(object sender, EventArgs e)
{
string time2;

for (int i = 0; i < listView2.Items.Count; i++)
{
ListViewItem lv = listView2.Items[i];
DataRow drNrow = dt2.NewRow();
drNrow[1] = lv.SubItems[0].Text;
drNrow[2] = lv.SubItems[1].Text;
drNrow[3] = lv.SubItems[2].Text;
drNrow[4] = lblreceiptno.Text;
drNrow[5] = txtcname.Text;
drNrow[6] = time2.ToString();
dt2.Rows.Add(drNrow);
da2.Update(dt2);
dt2.Rows.Clear();
da2.Fill(dt2);
}
}

It points on my DataAdapter.Update(DataTable);

These are my Codes. Thank you for your help. i appreciate it so much. I dont know why my Date Doesnt save as well as if i save Time from Label. My database is formatted as Date/Time, i use MS Access as my Database

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.