我試圖用已經存在的值(在同一行中)更新我的代碼,我得到下面的錯誤。通過SQL更新數據庫
這裏是代碼:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
string myInsertQuery = (String.Format("UPDATE tblUsers SET usersID='{0}', usersFirstName='{1}', " +
" usersLastName='{2}',usersPassword='{3}', usersAdress='{4}', usersMail ='{5}' " +
" WHERE usersID='{6}'", idn, firstName.Text, lastName.Text, password.Text, adress.Text
, mail.Text, idn));
OleDbCommand myCommand = new OleDbCommand(myInsertQuery);
myCommand.Connection = myConnection;
myConnection.Open();
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
這裏是錯誤:
System.Data.OleDb.OleDbException crossed a native/managed boundary
Message = mismatch in criteria expression
Source = Microsoft Office Access Database Engine
ErrorCode = -2147217913
我的數據庫中的參數是這樣定義的: 「usersID =號」,其餘的爲文本。
哇,與此SQL注入的可能性... – Tejs
請在使用參數化查詢一些研究(認爲:OleDbParameter),並保存自己的一些未來心痛。 –
由於你的用戶ID是數字字段,你可以使它像'UPDATE tblUsers SET usersID = {0}' – Rahul