Insert in OleDb does not work

  • Thread starter Thread starter mp
  • Start date Start date
M

mp

I have example like follows:

OleDbCommand InsertCommand =
new OleDbCommand("INSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
thisConnection);
InsertCommand.Parameters.Add("@ENGLESKI", OleDbType.VarChar);
InsertCommand.Parameters.Add("@SRPSKI", OleDbType.VarChar);

string[] reci = {textBox2.Text, textBox2.Text};
InsertCommand.Parameters["@ENGLESKI"].Value=reci[0];
InsertCommand.Parameters["@SRPSKI"].Value=reci[1];

This does not work.

If I use hard coded values instead reci[0] it does not work too. Interesting
is, if I use this example like command line project everything works
perfectly.

Does somebody know what is wrong?

Thanks
 
mp,
You forgot your fields in the INSERT command. Try
INSERT INTO RecnikTable field1, field2 VALUES
using, of course your own field names.

Ron Allen
 
I am sorry. Here is not solution.
I am confused because averything works with command line project but not
with win app.

Thanks

Michel R. said:
"Tu-Thach" <[email protected]> wrote in message
OleDb uses ? for parameters instead of @ENGLSKI, @SRPSKI.

Tu-Thach

----- mp wrote: -----

I have example like follows:

OleDbCommand InsertCommand =
new OleDbCommand("INSERT INTO RecnikTable VALUES (@ENGLESKI, @SRPSKI)",
thisConnection);
InsertCommand.Parameters.Add("@ENGLESKI", OleDbType.VarChar);
InsertCommand.Parameters.Add("@SRPSKI", OleDbType.VarChar);

string[] reci = {textBox2.Text, textBox2.Text};
InsertCommand.Parameters["@ENGLESKI"].Value=reci[0];
InsertCommand.Parameters["@SRPSKI"].Value=reci[1];

This does not work.

If I use hard coded values instead reci[0] it does not work too. Interesting
is, if I use this example like command line project everything works
perfectly.

Does somebody know what is wrong?

Thanks


Maybe you forgot to do an InsertCommand.ExecuteNonQuery at the end of your code???

Michel
 
Back
Top