Problems by inserting values from textboxes

Posted by simon on Stack Overflow See other posts from Stack Overflow or by simon
Published on 2010-04-28T16:10:38Z Indexed on 2010/04/28 17:23 UTC
Read the original article Hit count: 320

Filed under:
|

I'm trying to insert the current date to the database and i allways get the message(when i press the button on the form to save to my access database), that the data type is incorect in the conditional expression. the code:

string conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
         + "Data Source=C:\\Users\\Simon\\Desktop\\save.mdb";

            OleDbConnection empConnection = new OleDbConnection(conString);


            string insertStatement = "INSERT INTO obroki_save "
                                 + "([ID_uporabnika],[ID_zivila],[skupaj_kalorij]) "
                                 + "VALUES (@ID_uporabnika,@ID_zivila,@skupaj_kalorij)";

            OleDbCommand insertCommand = new OleDbCommand(insertStatement, empConnection);

            insertCommand.Parameters.Add("@ID_uporabnika", OleDbType.Char).Value = users.iDTextBox.Text;
                            insertCommand.Parameters.Add("@ID_zivila", OleDbType.Char).Value = iDTextBox.Text;
            insertCommand.Parameters.Add("@skupaj_kalorij", OleDbType.Char).Value = textBox1.Text;
            empConnection.Open();

            try
            {
               int count = insertCommand.ExecuteNonQuery();
            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                empConnection.Close();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
                textBox5.Clear();
            }

I have now cut out the date,( i made access paste the date ), still there is the same problem. Is the first line ok? users.idtextbox.text? Please help !

© Stack Overflow or respective owner

Related posts about c#

Related posts about date