代码如下,不知道什么原因编译后运行显示有一行错误。
private void btnSubmit_Click(object sender, System.EventArgs e)
{
SqlConnection objConnection=new SqlConnection(strConnection);
SqlCommand objCommand=new SqlCommand("CustOrdersOrders",objConnection);
objCommand.CommandType=CommandType.StoredProcedure;
SqlParameter objParameter=new SqlParameter("@CustomerID",SqlDbType.NChar,5);
objCommand.Parameters.Add(objParameter);
objParameter.Direction=ParameterDirection.Input;
objParameter.Value=lbCustomers.SelectedItem.Value;//此处出现错误。
objConnection.Open();
dgOutput.DataSource=objCommand.ExecuteReader();
dgOutput.DataBind();
objConnection.Close();
}
错误显示提示:未将对象引用设置到对象的实例。
private void btnSubmit_Click(object sender, System.EventArgs e)
{
SqlConnection objConnection=new SqlConnection(strConnection);
SqlCommand objCommand=new SqlCommand("CustOrdersOrders",objConnection);
objCommand.CommandType=CommandType.StoredProcedure;
SqlParameter objParameter=new SqlParameter("@CustomerID",SqlDbType.NChar,5);
objCommand.Parameters.Add(objParameter);
objParameter.Direction=ParameterDirection.Input;
objParameter.Value=lbCustomers.SelectedItem.Value;//此处出现错误。
objConnection.Open();
dgOutput.DataSource=objCommand.ExecuteReader();
dgOutput.DataBind();
objConnection.Close();
}
错误显示提示:未将对象引用设置到对象的实例。
解决方案 »
- ======================跪求~工作时间的计算!====================
- 给个Reporting Services的应用实例来看看
- |zyciis| 如何判断一个对像是否继承了System.Collections.ICollection 谢谢
- 招聘"网站运营总监"
- 如何得到GRIDVIEW中超级连接列的文本?
- 请问那有免费的下载的VisualStudio.NET_2003,我有一个为什么安装不上?
- active 控件使用的问题 高手请进!!
- IIS的问题:测到指定的WEB服务器运行的不是ASP。NET1。1的版本
- 如何获得herf后面URL值,要求使用正则表达式
- 高手请指点:在asp.net中使用客户端控件的解决方案
- asp.net操作sql数据库问题
- 求助:关于Access取一段时间范围内的数据问题
看看 lbCustomers这个id不对不呢?写错没有呢?
string selectID=lbCustomers.SelectedItem.Value
if(selectID==null||selectID="")
{
return;
}
objParameter.Direction=ParameterDirection.Input; (2)
objParameter.Value=lbCustomers.SelectedItem.Value--这句话你放到(1)语句前面看看
还是感谢大家的答复 。以下这个行不通的。没有定义怎么就可以先用了呢。
objCommand.Parameters.Add(objParameter); (1)
objParameter.Direction=ParameterDirection.Input; (2)
objParameter.Value=lbCustomers.SelectedItem.Value--这句话你放到(1)语句前面看看