自己的小例子供参考
SqlConnectioncon = new SqlConnection();
con.ConnectionString="server=WIN-07Q4IAKLGNF\\SQLEXPRESS;Integrated Security=true;Initial Catalog=注册登录";
con.Open();
SqlCommandadpt = new SqlCommand("insert into Table_1(username,password) values('"+Text1.Value+"','"+Password1.Value+"')", con);
adpt.ExecuteNonQuery();
con.Close();