以下是錯誤:對象引用(不知道我應該做的)
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
,並停止在這裏: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
確保您的查詢返回任何結果 –
它是返回結果我確定 – Marwan