SqlStr="SERVER=localhost;DATABASE=Mydb
;UID=sa;PWD=sa;"
SqlConnection
conn=new
Sqlconnection(SqlStr);
conn.open();
string
sql
=
"insert
into
users(name,pwd)
values(@name,@pwd)";
SqlCommand
cmd
=
new
SqlCommand(sql,conn);
SqlParameter
parn
=
new
SqlParameter("@name",Textbox1.text);
cmd.Parameters.Add(parn);
SqlParameter
parp
=
new
SqlParameter("@pwd",
Textbox2.text);
cmd.Parameters.Add(parn);
cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
类似这样,给Mydb数据库下一个名字叫users的拥有name、pwd两个属性的表赋值,把Textbox1的值传输给name,Textbox2的值传输给pwd.