【发布时间】:2012-06-06 16:48:23
【问题描述】:
这是错误:
异常详细信息:System.NullReferenceException:没有对象引用 设置为对象的实例。
它停在这里:con.Open();
这里是代码:
SqlConnection con = new SqlConnection(DBHelper.connection);
SqlCommand com = new SqlCommand();
con = com.Connection;
con.Open();
com.CommandType = CommandType.Text;
com.CommandText = "select catname,catdescription,photo from category where catid=" + catselectddl.SelectedValue ;
SqlDataReader dr= com.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
DataRow drr;
drr=dt.Rows[0];
con.Close();
错误:
Line 19: SqlCommand com = new SqlCommand();
Line 20: con = com.Connection;
Line 21: con.Open(); // here the error
Line 22: com.CommandType = CommandType.Text;
Line 23: com.CommandText = "select catname,catdescription,photo from category where catid=" + catselectddl.SelectedValue
【问题讨论】:
-
确保您的查询返回任何结果
-
我确定是返回结果