System.NullReferenceException: 未将对象引用设置到对象的实例

private void CourceDetailsShow()
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; //取出连接字符串
string SqlStr = "SELECT Cource.*,Teacher.teaName,Depart.departName from Cource,Teacher ,Depart where Cource.teaID=Teacher.teaID and Cource.courceID='" + Request["courceID"].ToString() + "' and Cource.teaID='" + Request["teaID"].ToString() + "'and Depart.departID='" + Request["courceDepart"] + "'";
SqlConnection conn = new SqlConnection(connStr); //创建连接对象
try
{
if (conn.State.ToString() == "Closed") //连接如果关闭,打开
conn.Open();
SqlCommand cmd = new SqlCommand(SqlStr, conn);
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
courceName.Text = sdr["courceName"].ToString();
txtName.Text = sdr["courceName"].ToString();
ddlTeacherName.SelectedItem.Text = sdr["teaName"].ToString();
txtDepart.Text = sdr["departName"].ToString();
txtTime.Text = sdr["courceTime"].ToString();
txtAddress.Text = sdr["courceAddress"].ToString();
txtDetails.Text = sdr["courceInfo"].ToString();
}
else
{
Response.Write("数据库错误,没查询到该门课程!");
Response.End();
}
}

上面是主要的代码,但是就是一直提示System.NullReferenceException: 未将对象引用设置到对象的实例,也找不出哪里错,急!!!

1个回答

Request["xxx"]
这些都可能不存在。仔细调试下,才知道问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐