关于"未将对象引用设置到对象的实例"的若干解释
今天小康写程序写到编辑页面的时候报错了,经检查ID值的确从列表页递交出去了,但是在接数据的时候出了点小问题,于是就出现了
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL.example;
using Model.example;
namespace Web.example
{
public partial class ProductUpdate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int productid = int.Parse(Request.QueryString["productid"].ToString().Trim());
Product product = ProductDAL.GetProductByID(productid);
tbProductid.Text = product.Productid.ToString();
tbName.Text = product.Name;
DateTextBox1.Text = product.Date.ToString();
tbSize.Text = product.Size;
tbVersion.Text = product.Version;
tbColor.Text = product.Color;
DataSet ds = new SortDAL().GetSortDataSet();
ddSortid.Items.Add(new ListItem("---请选择---", "-1"));
foreach (DataRow dr in ds.Tables[0].Rows)
{
ddSortid.Items.Add(new ListItem(dr["name"].ToString(), dr["sortid"].ToString()));
}
ddSortid.SelectedValue = product.Storid.ToString();
}
}
using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;
using DAL.example;using Model.example;
namespace Web.example{ public partial class ProductUpdate : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int productid = int.Parse(Request.QueryString["productid"].ToString().Trim()); Product product = ProductDAL.GetProductByID(productid); tbProductid.Text = product.Productid.ToString(); tbName.Text = product.Name; DateTextBox1.Text = product.Date.ToString(); tbSize.Text = product.Size; tbVersion.Text = product.Version; tbColor.Text = product.Color;
DataSet ds = new SortDAL().GetSortDataSet(); ddSortid.Items.Add(new ListItem("---请选择---", "-1")); foreach (DataRow dr in ds.Tables[0].Rows) { ddSortid.Items.Add(new ListItem(dr["name"].ToString(), dr["sortid"].ToString())); } ddSortid.SelectedValue = product.Storid.ToString(); } }
纠结一个小时以后发现犯了一个非常弱智的问题上图
检查后发现竟然是函数写错了.....
汗一个。
问题解决
aaaaaaaa