我的目标是让SQL检查该行是否存在,如果它更新,如果不插入。SQL如果不存在插入else更新,根据列ID
FTP_num
是第一列的名称。 SQL Statement是
using (SqlCommand cmd = new SqlCommand("IF NOT EXISTS(SELECT ftp_num from Distributor WHERE fpt_num = FTP_num)"
" insert FTP_Info set [email protected], [email protected], [email protected], [email protected], [email protected] where FTP_num = @ftp_num" +
" else" +
" update FTP_Info set [email protected], [email protected], [email protected], [email protected], [email protected] where FTP_num = @ftp_num", con))
我没有太多的SQL经验,任何帮助表示赞赏。
Line 120:
Line 121: con.Open();
Line 122: cmd.ExecuteNonQuery();
Line 123: con.Close();
Line 124: }
您使用的是什么RDBMS? –
基于c#代码使用SqlCommand我猜对了Sql server –
Microsoft SQL Server。 SQL Server 2014 –