日期:2014-05-17  浏览次数:20491 次

在vs2010中连接sqlserver2005的代码怎么写,请高手指点
如题,知道的大侠指教下哦,附上代码,并简单的说明,谢啦
------最佳解决方案--------------------
 password == "")  //没有输入用户名或者密码给予提示              {                  MessageBox.Show("请输入完整的用户名和密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);              }              else             {                  string connString = @"Data Source=.\SQLEXPRESS;Initial Catalog=Book;Integrated Security=True";                  SqlConnection connection = new SqlConnection(connString);   //连接到引入的数据库                     connection.Open();  // 打开数据库连接                    string sql = String.Format("select count(*) from [User] where workerno='{0}'and password='{1}' and level= '{2}'", userNo, password, levels);  //获取     用户名和密码匹配的行的数量的SQL语句                     SqlCommand command = new SqlCommand(sql, connection);   //创建 Command 对象                  int num = (int)command.ExecuteScalar();  //执行查询语句,返回匹配的行数                  if (num > 0)    //如果有匹配的行,则表明用户名、密码和权限正确                  {                                             MessageBox.Show("欢迎进入图书仓库管理系统!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information);                      this.Hide();  //隐藏登录窗体                      MainFrm mainForm = new MainFrm();// 创建主窗体对象                       if (levels == "普通管理员")  //如果是普通管理员登录,怎不能使用员工信息的功能                      {                          mainForm.levels1();  //调用主函数中自己定义的函数(不能使用员工信息的供能)                      }            &n