Hi people,
I am create table in access mdb with name Potrazivanje.
Than i create 3 columns and fill it with data.
Columns name in table Potrazivanje UserName, Order, Field3
What i want ?
I want find in table Potrazivanje UserName and insert text string in
Field3 who is in same row as UserName.
I try with this but i get some error with command string
string baza = dostupno.alpoExePath + "\\" + "alpo_doo_database.mdb";
string conAccSt = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; OleDbConnection conn = null;
conn = new OleDbConnection(conAccSt + baza);
conn.Open();
string st = comboBox1.Text;
OleDbCommand update = new OleDbCommand("UPDATE Potrazivanje SET Uneo = '" + Order + "', WHERE UserName= '" + st + "'", conn);
update.ExecuteNonQuery();
conn.Close();
I use winForms
Thanks for Help
Wim SturkenboomPosted Sep 29, 2014, 7:16 AM
I try with this but i get some error with command string
[/quote]
No, you don't get some error; you get a detailed error that you can post here ;)
[quote]
OleDbCommand update = new OleDbCommand("UPDATE Potrazivanje SET Uneo = '" + Order + "', WHERE UserName= '" + st + "'", conn);
[/quote]
I assume that it's the comma.
Further I suggest that you read up on parameter queries. You should never directly pass values into sql strings (not for select nor for anything else).
The right way will be something like
System.Data.OleDb.OleDbCommand update = new System.Data.OleDb.OleDbCommand("UPDATE Potrazivanje SET Uneo = @pOrder WHERE UserName= @pST", conn);
update.Parameters.AddWithValue("@pOrder", Order);
update.Parameters.AddWithValue("@pST", st);
I use the p to indicate that it is a parameter.
Note:
not tested, but it should give you the idea.
sasa lazicPosted Sep 29, 2014, 10:41 AM
Problem comma