本人学生 用vs做前台 打算做个图书管理的小程序 是数据库的期末作业 刚学了俩月比较菜 老师在没有教过做前台的情况下让我们自己做这个作业 时间也很紧张 测试程序一直显示无法登陆数据库 但是如图vs已经连接上这个数据库了 数据库就在本机 不知道什么原因 在网上零零散散试了很多方法 关防火墙 改用户权限 用sa登陆 都行不通 真的很着急 希望大神帮帮我
可以打开master
点击登陆之后的代码:
if (rad管理员.Checked == true)
{
string connString = "Data Source=.;Initial Catalog=图书管理系统;user id=sa;password=991661";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
//连接数据库
string strSQL = "select * from [admin] where 管理员名称='" + txtID.Text + "' and 密码='" + txt密码.Text + "'";//表示要对 SQL Server 数据库执行的一个SQL语句
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader read = cmd.ExecuteReader();
read.Read();
if (read.HasRows)
{
管理员界面 管理员界面 = new 管理员界面();
this.Hide();
管理员界面.Text = "管理员界面";
管理员界面.Show();
}
else
{
MessageBox.Show("登录失败,请检查密码是否正确!");
}
conn.Close();
}
if (rad学生.Checked == true)
{
string connString = "Data Source=REANNY;Initial Catalog=图书管理系统;Integrated Security=True ";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
//连接数据库
string strSQL = "select * from [user] where 用户名='" + txtID.Text + "' and 密码='" + txt密码.Text + "'";//表示要对 SQL Server 数据库执行的一个SQL语句
SqlCommand cmd = new SqlCommand(strSQL, conn);
SqlDataReader read = cmd.ExecuteReader();
read.Read();
if (read.HasRows)
{
this.Hide();
管理员界面 读者界面 = new 管理员界面();
读者界面.Value = 1;
读者界面.Show();
读者界面.Text = "读者界面";
}
else
{
MessageBox.Show("登录失败,请检查密码是否正确!");
}
conn.Close();
}