C# 如何在页面加载asp.net中运行命令sql insert code?
我想将许多记录从C# 如何在页面加载asp.net中运行命令sql insert code?,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我想将许多记录从profile\u tb复制到Client\u tb而不复制。 这段代码在sql server中运行得很好,但我不知道以下代码是否已添加到asp.net中的客户端页面加载中 Sql命令: iNSERT iNTO Client (ProfileID) Select Distinct ProfileId From Profile Where Not Exists (Select 1 From Client where Profile.ProfileID = Client.Profi
profile\u tb
复制到Client\u tb
而不复制。
这段代码在sql server中运行得很好,但我不知道以下代码是否已添加到asp.net中的客户端页面加载中
Sql命令:
iNSERT iNTO Client (ProfileID)
Select Distinct ProfileId From Profile Where Not Exists (Select 1 From
Client where Profile.ProfileID = Client.ProfileID )
请帮帮我 查看SqlConnection、SqlCommand类
using (SqlConnection cn = new SqlConnection("your connection string")) {
SqlCommand cmd = new SqlCommand("INSERT iNTO Client (ProfileID) Select Distinct ProfileId From Profile Where Not Exists (Select 1 From Client where Profile.ProfileID = Client.ProfileID )", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close(); }
但是,我建议您更多地研究SqlCommand,如果这是网站代码,则使用参数方法来防御SQL注入攻击