有关对象不能从 DBNull 转换为其他类型问题
我想做网上购物系统,但运行就出现这种错误,请各位兄弟是什么原因
源错误:
行 118: {
行 119: DataRow r = dt.NewRow();
行 120: r[0] = Convert.ToInt32(ds1.Tables[0].Rows[i]["ID"]);
行 121: r[1] = ds1.Tables[0].Rows[i]["Sort"].ToString();
行 122: r[2] = Convert.ToInt32(ds1.Tables[0].Rows[i]["ProductID"]);
源文件: c:\inetpub\wwwroot\webapplicationdlh21\wsgw\gouwuche.aspx.cs 行: 120
堆栈跟踪:
[InvalidCastException: 对象不能从 DBNull 转换为其他类型。]
System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) +48
System.Convert.ToInt32(Object value) +36
WebApplicationDlh21.Wsgw.Gouwuche.dtBind() in c:\inetpub\wwwroot\webapplicationdlh21\wsgw\gouwuche.aspx.cs:120
WebApplicationDlh21.Wsgw.Gouwuche.dgGouwucheBind() in c:\inetpub\wwwroot\webapplicationdlh21\wsgw\gouwuche.aspx.cs:100
WebApplicationDlh21.Wsgw.Gouwuche.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplicationdlh21\wsgw\gouwuche.aspx.cs:65
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731