[英]An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll 430
the da.fill(ds) is giving me an An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll da.fill(ds)给我一个System.Data.dll中发生的'System.InvalidOperationException'类型的未处理异常
I'm not 100% sure why this error is here but I know it appeared after I attempted this login code. 我不确定100%为何会出现此错误,但我知道在尝试登录代码后会出现此错误。
using (SqlConnection con = new SqlConnection("Data Source=c:\\RegistrationMDB.accdb"))
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("SELECT ID, PASSWORD FROM Students WHERE ID = @ID OR PASSWORD = @PASSWORD", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = id;
cmd.Parameters.Add("@PASSWORD", SqlDbType.VarChar).Value = pw;
da.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
iD = (dr["@ID"].ToString());
password = dr["@PASSWORD"].ToString();
}
if (iD == id && password == pw)
{
return true;
}
else
{
LogNotification = "ID/Password is incorrect";
return false;
}
}
}
da.SelectCommand = cmd;
在da.Fill(ds);
之前da.Fill(ds);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.