您的位置:首页 > 数据库

C# 连接SQL Server 2000 数据库核心代码

2008-11-22 23:09 471 查看
SqlConnection c = new SqlConnection("User ID=sa;Initial Catalog=Admin;Data Source=799BE7EF4229458");
c.Open();

MessageBox.Show(c.State.ToString());//显示数据连接状态

string sql="insert into t1(Name,Pwd) values (@a,@b)";
SqlParameter p1 = new SqlParameter("@a", textBox1.Text);
SqlParameter p2 = new SqlParameter("@b", textBox2.Text);

SqlCommand com = new SqlCommand(sql, c);
com.Parameters.Add(p1);
com.Parameters.Add(p2);
com.ExecuteNonQuery();
MessageBox.Show("Register is successful !");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: