连接sqlserver数据库

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();

你可能感兴趣的:(连接sqlserver数据库)