为什么我的代码无法更新?
代码:
//Create a new Insurance
Insurance oInsurance = new Insurance();
oInsurance.Active = true;
oInsurance.Address1 = txtAddress.Text;
oInsurance.Address2 = txtAddress.Text;
oInsurance.Name = txtName.Text;
oInsurance.City = txtCity.Text;
oInsurance.BillingProviderAddress = txtNameSubmit.Text;
答案 0 :(得分:4)
要更新记录,您必须传递表的主/唯一键。在传递其他参数时,必须将键列传递给更新,
oInsurance.PrimaryKey/UniqueColumnName = Value;
最后,当构建查询时,它将错过 where 部分,
update table set columnName=@Value where ID = ?
答案 1 :(得分:1)
尝试更新记录时,应传递唯一值以更新该特定记录或一组记录(有时可能是主键),
update tablename set columnName=@columnvalue where uniquerecordkey = @identifyingkeyvalue