C#数据库项目,运行出现错误:“未将对象引用设置到对象的实例”。代码如下:
publicstaticvoidCheckStudent(stringStuNo,stringPwd){try{SqlConnectionconn=newSqlConne...
public static void CheckStudent(string StuNo,string Pwd)
{
try
{
SqlConnection conn = new SqlConnection(connStr);
string sqlStr = "SELECT * FROM Student WHERE StuNo = @StuNo AND Pwd=@Pwd";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sqlStr;
cmd.Parameters.Add("StuNo",SqlDbType.NVarChar,8).Value=StuNo;
cmd.Parameters.Add("Pwd",SqlDbType.NVarChar,8).Value = Pwd;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
LoginInfo[0] = dr[0];
}
else
LoginInfo = null;
}
catch(Exception ex)
{
throw ex;
}
} 展开
{
try
{
SqlConnection conn = new SqlConnection(connStr);
string sqlStr = "SELECT * FROM Student WHERE StuNo = @StuNo AND Pwd=@Pwd";
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = sqlStr;
cmd.Parameters.Add("StuNo",SqlDbType.NVarChar,8).Value=StuNo;
cmd.Parameters.Add("Pwd",SqlDbType.NVarChar,8).Value = Pwd;
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
LoginInfo[0] = dr[0];
}
else
LoginInfo = null;
}
catch(Exception ex)
{
throw ex;
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询