我是asp.net的初学者,我开发了一个使用DB的网站,但在尝试连接到数据库时我总是遇到这个异常:
类型' System.Data.SqlClient.SqlException'未处理的异常发生在System.Data.dll
中这是代码:
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Server = (local)\\ASP2010;Database = accedint_DB;Integrated Security = true");
SqlCommand com = new SqlCommand();
com.CommandType = CommandType.Text;
com.Connection = con;
com.CommandText = "select EMPLOYEE_ID from EMPLOYEE_INFO where USER_NAME = @Name and USER_PASS = @Pass";
com.Parameters.AddWithValue("@Name", textBox1.Text);
com.Parameters.AddWithValue("@Pass", textBox2.Text);
if (con.State == ConnectionState.Closed)con.Open();
string UserID;
UserID = Convert.ToString(com.ExecuteScalar());
if (UserID =="")
MessageBox .Show ("Login fail , Please try again");
else if (comboBox1.Text.ToLower() == "admin")
{
Form2 f2 = new Form2();
f2.EmpID = Convert.ToInt32(UserID);
f2.EmpName = textBox1.Text;
f2.Show();
}
else if (comboBox1.Text.ToLower() == "employee") {
Form10 f10 = new Form10();
f10.EmpID = Convert.ToInt32(UserID);
f10.EmpName = textBox1.Text;
f10.Show();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Text.ToLower() == "admin")
{
Form5 f2 = new Form5();
f2.EmpName = EmpName;
f2.Show();
}
else if (comboBox1.Text.ToLower() == "employee") {
Form4 f10 = new Form4();
f10.EmpName = EmpName;
f10.Show();
}
}
答案 0 :(得分:0)