这里aspx页面上有两个TextBox控件,名称分别为userName 和 pwd.还有一个submit按钮,以下代码都是写在按钮的时间中的:(截图如下)

1.直接用SqlCommand写sql语句:
String strusername = this.userName.Text;
String strpwd = this.pwd.Text;
SqlConnection conn = new SqlConnection();
SqlCommand comm = new SqlCommand();
conn = new SqlConnection("server=localhost;database=demo;uid=sa;pwd=123456");
conn.Open();
comm.Connection = conn;
comm.CommandText = "insert into demo(username,pwd) values('" + strusername + "','" + strpwd + "')";
comm.ExecuteNonQuery();


SqlConnection conn = new SqlConnection();







2.用SqlDataAdapter和DataTable:




String strusername = this.userName.Text;














3.用SqlDataAdapter和DataSet:

















OK,超级简单吧,哦是菜鸟~~~じゃあ、一緒に頑張ろう!