我无法弄清楚问题在这里,因为附加信息回复为:'''附近的语法不正确。我想我需要注意这一点,我看不出错误。
这是我的代码,我试图将信息更新为所选的Owner_ID。
System.Data.SqlClient.SqlCommand command = new SqlCommand("UPDATE OwnerTable SET (Owner_ID, Owner_Fname, Owner_Lname, Owner_HouseNo, Owner_Street, Owner_County, Owner_PostCode, Owner_Tele, Owner_Email) VALUES (@OwnerID, @OwnerFName, @OwnerLName, @OwnerHouseNo, @OwnerStreet, @OwnerCounty, @OwnerPostCode, @OwnerTele, @OwnerEmail) WHERE Owner_ID = @OwnerID", connection);
command.CommandType = CommandType.Text;
command.Connection = connection;
command.Parameters.AddWithValue("@OwnerID", CB_OWNER_ID.GetItemText(CB_OWNER_ID.SelectedItem));
command.Parameters.AddWithValue("@OwnerFName", TXT_OWNER_FNAME.Text);
command.Parameters.AddWithValue("@OwnerLName", TXT_OWNER_LNAME.Text);
command.Parameters.AddWithValue("@OwnerHouseNo", TXT_OWNER_HOUSENO.Text);
command.Parameters.AddWithValue("@OwnerStreet", TXT_OWNER_STREET.Text);
command.Parameters.AddWithValue("@OwnerCounty", TXT_OWNER_COUNTY.Text);
command.Parameters.AddWithValue("@OwnerPostCode", TXT_OWNER_POSTCODE.Text);
command.Parameters.AddWithValue("@OwnerTele", TXT_OWNER_TELE.Text);
command.Parameters.AddWithValue("@OwnerEmail", TXT_OWNER_EMAIL.Text);
答案 0 :(得分:3)
您使用INSERT
语法而不是UPDATE
语法:
UPDATE OwnerTable SET Owner_ID = @OwnerID, Owner_Fname = @OwnerFName ..etc
或者,如果您确实想插入新记录更改UPDATE
到INSERT INTO
并删除WHERE
(但我猜WHERE
表示您想要更新。
顺便说一下:您确定要更新OwnerID
中的OwnerTable
吗?对我来说似乎不对。