未处理 System.Data.SqlClient.SqlException
小弟调试网上下载的程序出了问题了 但是除了这个问题
未处理 System.Data.SqlClient.SqlException
部分代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 实验室设备管理系统
{
public partial class 登录 : Form
{
public static string name;
public static string password;
public static string entry;
public 登录()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void 登录_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text == "" || this.textBox2.Text == "")
MessageBox.Show("请输入用户名和密码");
else
{
SqlConnection con = new SqlConnection(); //创建连接
con.ConnectionString = "server=(local);database=实验室设备;uid=sa;pwd=";
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText ="select *from 登录";
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string power = dr[0].ToString();
主界面 main = new 主界面();
main.Tag = this.FindForm();
this.Visible = false;
main.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("用户名或密码错误");
}
con.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public void textBox1_TextChanged(object sender, EventArgs e)
{
name = this.textBox1.Text;
SqlConnection con = new SqlConnection(); //创建连接
con.ConnectionString = "server=(local);database=实验室设备;uid=sa;pwd=";
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select 权限 from 登录 where 姓名='" + this.textBox1.Text + "'";
SqlDataReader sqlread = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (sqlread.Read())
{
label4.Text = sqlread["权限"].ToString();
entry =this.label4.Text.Trim();
con.Close();
}
}
public void textBox2_TextChanged(object sender, EventArgs e)
{
password = this.textBox2.Text;
}
private void label4_Click(object sender, EventArgs e)
{
}
}
}
谁能帮我看看啊?