我的目標是讓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 –