美文网首页
连接sqlserver数据库

连接sqlserver数据库

作者: 第七空城 | 来源:发表于2017-05-28 00:04 被阅读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();

相关文章

网友评论

      本文标题:连接sqlserver数据库

      本文链接:https://www.haomeiwen.com/subject/enfcfxtx.html