嗨,我儘量讓多級別的登錄,所以我用這個代碼,但它不工作C#多級用戶登錄
「System.InvalidOperationException」類型發生在System.Data未處理的異常.dll文件
其他信息:無效嘗試時不存在數據讀取。
錯誤是表現出對string s1 = dr[3].ToString();
CODE:
private void button3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Server=GATEWAY-PC\SQLSERVER;Initial Catalog=train_system;Integrated Security=True";
SqlCommand cmd = new SqlCommand("SELECT * FROM employer WHERE username='" + textBox1.Text + "'AND password='" + textBox2.Text + "'",conn);
conn.Open();
SqlDataReader dr ;
dr = cmd.ExecuteReader();
int count = 0;
while (dr.Read())
{
count += 1;
}
if (count == 1)
{
string s1 = dr[3].ToString();
if (s1 == "1")
{
MessageBox.Show("Login as Shedule");
}
else if (s1 == "2")
{
MessageBox.Show("Login as Operation");
}
}
else if (count < 1)
{
MessageBox.Show("error");
}
}
請出示僱主表的模式 – DarkKnight