Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在页面加载asp.net中运行命令sql insert code?_C#_Asp.net_Sql Server - Fatal编程技术网

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注入攻击