【发布时间】:2013-06-06 21:08:03
【问题描述】:
对象引用未设置为对象的实例。
这是我在尝试从网格视图中删除 .. 行时遇到的错误
这是在 ..page_load 中
gvDetails.DataSource =myBl.DeleteAllCountry(int.Parse(gvDetails.SelectedRow.ToString()));
关于数据访问层
public DataTable DeleteCountry(int country_id)
{
DataTable dltcontry = new DataTable();
SqlConnection con = new SqlConnection(@"Data Source=a8-pc\sqlexpress;Integrated Security=True");
SqlDataAdapter da;
try
{
SqlCommand cmd = new SqlCommand();
cmd.connection= con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_DeleteCountry";
con.Open();
da = new SqlDataAdapter(cmd);
cmd.Parameters.AddWithValue("country_id", @country_id);
cmd.ExecuteNonQuery();
da.Fill(dltcontry);
con.Close();
}
在业务层代码就像
public DataTable DeleteAllCountry(int country_id)
{
return mydtLayer.DeleteCountry(country_id);
}
【问题讨论】:
-
请正确格式化您的问题并使用正确的英文..这不是短信..
-
你有删除的存储过程,你可以通过调用
ExecuteNonQuery来删除,但为什么你又用同样的方法来获取数据? -
请更清楚地说明您的问题。此异常看起来像 NullPointer-Exception。通常调试输出提供异常发生的行号,包括堆栈跟踪。使用该行号进一步调查错误。