连接sqlserver数据库

2017-05-28  本文已影响0人  第七空城

1.连接服务器:本地;账户:sa;密码:***;数据库:saier;

string strConnect = "server =.;uid = sa; pwd = ***;database = saier";

2.执行sql语句对数据库进行操作

 SqlConnection conConnection = new SqlConnection(strConnect);

 conConnection.Open();
 string cmd="insert into zhanghao values('"+textBox1.Text+"',"+"'"+textBox2.Text+"'"+")"; 
 SqlCommand com=new SqlCommand(cmd,conConnection);
 com.ExecuteNonQuery();//执行sql
 conConnection.Close();
上一篇 下一篇

猜你喜欢

热点阅读