在.net中向sql数据表里面写入数据行
private void Button1_Click(object sender, System.EventArgs e)
  {
   string t1;
   t1 = this.TextBox1.Text;
   string abc;
   abc = this.TextBox2.Text;
   //建立数据库连接
   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 ();
}
posted on 2006-01-23 22:06 Dina's blog 阅读(367) 评论(0) 收藏 举报
 
                    
                 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号