| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 674 人关注过本帖
标题:[求助]执行程序时候显示“未将对象引用设置到对象的实例”
只看楼主 加入收藏
host1982
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2005-8-7
收藏
 问题点数:0 回复次数:1 
[求助]执行程序时候显示“未将对象引用设置到对象的实例”

protected void UpdateShoppingCart()
{
if(AddProdCount==0)
{
CreateCartTable();
SubTotal.Text="0.00";
Tax.Text="0.00";
Total.Text="0.00";
}
else
{
DataTable nowTable=new DataTable("nowCartTable");
nowTable=(DataTable)Session["myCartTable"];
int pn=nowTable.Rows.Count;

int i=0;
bool hasone=false;
int nowProdID;
while(i<pn && !hasone)
{
nowProdID=Int32.Parse(nowTable.Rows[i][0].ToString());
if(nowProdID==AddProdID)
{
hasone=true;
}
else
{
i++;
}
}
if(hasone)
{
DataRow oldDR;
oldDR=nowTable.Rows[i];

oldDR["ProdCount"]=Int32.Parse(oldDR["ProdCount"].ToString())+1;
oldDR["TotalPrice"]=Int32.Parse(oldDR["ProdCount"].ToString())*Double.Parse(oldDR["UnitPrice"].ToString());
}
else
{
DataRow newDR;
double unitp;

SqlConnection myConnection=new SqlConnection("server=.;database=Aspnet;uid=sa;pwd=;");
string strSQL="select * from Products where ProductID="+AddProdID+"";
SqlDataAdapter myCommand=new SqlDataAdapter(strSQL,myConnection);
myCommand.Fill(ds,"Addp");

newDR=nowTable.NewRow();
newDR[0]=AddProdID;

newDR[2]=ds.Tables["AddP"].Rows[0]["ProductName"].ToString();

unitp=Double.Parse(ds.Tables["AddP"].Rows[0]["UnitPrice"].ToString());
newDR[3]=unitp;
newDR[4]=unitp;
nowTable.Rows.Add(newDR);
}
ShoppingCartDlt.DataSource=nowTable.DefaultView;
ShoppingCartDlt.DataBind();

Session["myCarTable"]=nowTable;

double subt=0;
pn=nowTable.Rows.Count;
for(i=0;i<pn;i++)
{
subt+=Double.Parse(nowTable.Rows[i]["TotalPrice"].ToString());
}
this.DisplayMoney(subt);
}

}
以上的程序显示了黑体字部分如下错误:
未将对象引用设置到对象的实例
黑体字上面的那一句在下面的代码里定义了(黑体部分)
protected void CreateCartTable()
{
DataTable newDT=new DataTable("CartTable");
ds.Tables.Add(newDT);

DataColumn newDC;
newDC=new DataColumn("ProdID",System.Type.GetType("System.Int32"));
ds.Tables["CartTable"].Columns.Add(newDC);
newDC=new DataColumn("ProdCount",System.Type.GetType("System.Int32"));
newDC.DefaultValue=1;

ds.Tables["CartTable"].Columns.Add(newDC);
newDC=new DataColumn("ProdName",System.Type.GetType("System.String"));

ds.Tables["CartTable"].Columns.Add(newDC);
newDC=new DataColumn("UnitPrice",System.Type.GetType("System.Double"));

ds.Tables["CartTable"].Columns.Add(newDC);
newDC=new DataColumn("TotalPrice",System.Type.GetType("System.Double"));
ds.Tables["CartTable"].Columns.Add(newDC);

Session["myCartTable"]=newDT;

ShoppingCartDlt.DataSource=ds.Tables["CartTable"].DefaultView;
ShoppingCartDlt.DataBind();
}

搜索更多相关主题的帖子: 执行程序 实例 对象 
2006-01-12 11:38
islet
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:89
帖 子:6548
专家分:0
注 册:2005-1-28
收藏
得分:0 
Session["myCartTable"]不是对象实例
2006-01-14 11:02
快速回复:[求助]执行程序时候显示“未将对象引用设置到对象的实例”
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014665 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved