如何在页面加载asp.net中运行命令sql insert代码?

时间:2016-04-24 10:32:12

标签: c# asp.net sql-server

我想将许多记录从PictureBox复制到pictureBox1.Image = bmp ; ,不会重复。 这段代码在sql server中运行得非常好,但我不知道以下代码被添加到asp.net中的客户端页面加载。

Sql命令:

profile_tb

请帮助我!

1 个答案:

答案 0 :(得分:0)

查看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,如果这是网站代码,请使用Parameters方法来抵御SQL注入攻击。