Sql write data into the data table row inside in .net

private void Button1_Click(object sender, System.EventArgs e)
  {
   string t1;
   t1 = this.TextBox1.Text;

   string abc;
   abc = this.TextBox2.Text;


   // Create a database connection
   System.Data.SqlClient.SqlConnection ab123 = new System.Data.SqlClient.SqlConnection ( "server = (local); database = TestNews; uid = sa; pwd = sa;");

   string qiandan = "INSERT INTO News (Title,content)  VALUES ('" + t1 + "','" + abc + "')";

   System.Data.SqlClient.SqlCommand ef = new System.Data.SqlClient.SqlCommand(qiandan,ab123);

   ef.Connection.Open();
   ef.ExecuteNonQuery();

   


  }

  private void Button2_Click(object sender, System.EventArgs e)
  {
   string a;
   a=this.TextBox3.Text;
   string b;
   b=this.TextBox4.Text;

   System.Data .SqlClient.SqlConnection abb= new System.Data.SqlClient.SqlConnection("server=(local);database=Hotel;uid=sa;pwd=sa;");
   string qd="INSERT INTO TABLE1( date,name) VALUES ('"+a+"','"+b+"')";
   System.Data .SqlClient .SqlCommand ef= new System.Data.SqlClient.SqlCommand(qd,abb);
   ef.Connection.Open();
      ef.ExecuteNonQuery ();

  }

Reproduced in: https: //www.cnblogs.com/qiandan/archive/2006/01/23/322297.html

Guess you like

Origin blog.csdn.net/weixin_34194317/article/details/92842357