我试图对不存在的客户 ID 进行验证。如果 ID 存在,则报表将显示该 ID 的记录,如果不存在,则提示错误。但即使我尝试输入存在的客户 ID,也会提示错误。
错误:对象引用未设置为对象的实例。
string sql = "SELECT whbal.customer, customer.imp_license_no, customer.psq_level, " +
"CONVERT(DECIMAL(8,3),SUM(CASE WHEN whbal.warehouse='SKW' THEN (CONVERT(DECIMAL(8,3),whbal.qty_good) + CONVERT(DECIMAL(8,3),whbal.qty_slack)) * CONVERT(DECIMAL(8,3),whbal.std_weight) /1000 ELSE 0.0 END)) AS SENOKO, " +
"FROM customer INNER JOIN whbal ON whbal.customer=customer.customer AND whbal.date_create<=@date1 " +
"INNER JOIN stktype ON whbal.stock_type=stktype.stock_type " +
"WHERE whbal.customer BETWEEN @cust1 AND @cust2 AND whbal.stock_type=@type " +
"GROUP BY whbal.customer, customer.imp_license_no,customer.psq_level";
SqlCommand custcom = new SqlCommand(sql, myconnection);
custcom.Parameters.AddWithValue("@cust1", cboFrom.SelectedValue.ToString());
custcom.Parameters.AddWithValue("@cust2", cboTo.SelectedValue.ToString());
custcom.Parameters.AddWithValue("@type", cboStk.SelectedValue.ToString());
custcom.Parameters.AddWithValue("@date1", dateTimePicker1.Value);
SqlDataAdapter da = new SqlDataAdapter(custcom);
DataSet1 ds = new DataSet1();
da.Fill(ds, "customer1");
DataTable dt = new DataTable();
da.Fill(dt);
myconnection.Close();
if (dt.Rows.Count > 0)
{
code...
}
else if (dt.Rows.Count <= 0)
{
MessageBox.Show("Customer not existed.");
}
有谁知道是什么问题,请指导和建议。