【发布时间】:2019-12-08 05:41:27
【问题描述】:
我需要这方面的帮助
string query = @"IF EXISTS(Select * From u_Data Where TAG = '" + txtTag.Text + "') begin Update u_data set Name = '" + txtNama.Text +
"', NIK = '" + txtNIK.Text + "', Department = '" + txtDept.Text + "' where Tag = '" + txtTag.Text +
"' end else begin Insert Into u_data (TAG, Name, NIK, Department) VALUES ('" + txtTag.Text + "', '" + txtNama.Text + "', '" + txtNIK.Text + "', '" + txtDept.Text + "') end";
SqlCommand cmd = new SqlCommand(query, con);
根本无法更新 & 只会插入
【问题讨论】:
-
尝试在 SQL 管理工作室中使用适当的值运行相同的查询。它在那里运行成功吗?
-
Bobby Tables 刚刚要求添加部门
');drop table department;--。但我莫名怀疑他的诚意?顺便说一句,还有一个 MERGE 声明用于 upserts。
标签: c# sql-server sqlcommand