Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html “我如何解决?”;对象引用未设置为对象的实例";?_Html_Asp.net_Gridview_Ado.net - Fatal编程技术网

Html “我如何解决?”;对象引用未设置为对象的实例";?

Html “我如何解决?”;对象引用未设置为对象的实例";?,html,asp.net,gridview,ado.net,Html,Asp.net,Gridview,Ado.net,这是页面加载,我在数据表中创建了两列,并使用下拉列表连接数据库: protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[2] { new DataColumn("product_name"),

这是页面加载,我在数据表中创建了两列,并使用下拉列表连接数据库:

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)  
    {    
        DataTable dt = new DataTable();  
        dt.Columns.AddRange(new DataColumn[2] { new   DataColumn("product_name"), new DataColumn("Quantity") });  
        ViewState["sales"] = dt;  
        GridView1.DataBind();  

        txt_productname.DataSource = sic.get_product_name_for_textbox();  
        txt_productname.DataTextField = "product_name";  
        txt_productname.DataValueField = "product_id";  
        txt_productname.DataBind();  

        txt_customername.DataSource =   sic.get_customer_name_for_textbox();  
        txt_customername.DataTextField = "customer_name";  
        txt_customername.DataValueField = "customer_id";  
        txt_customername.DataBind();  
    }  
代码端这是一个临时数据网格:

protected void btn_insert_Click(object sender, EventArgs e)
    if (string.IsNullOrWhiteSpace(txt_productname.Text) ||string.IsNullOrWhiteSpace(txt_quantity.Text))
    {
        Response.Write("<script LANGUAGE='JavaScript'>alert('NotAllowNull')     </script>");  
    }
    else
    {
        DataTable dt = null;
        if (Session["DataTable"] != null)
            dt = (DataTable)Session["DataTable"];
        else
        {
        }

        dt.Rows.Add(txt_productname.SelectedValue.ToString());
        dt.Rows.Add(txt_quantity.Text);

        GridView1.DataSource = dt;
        GridView1.DataBind();
        Session["DataTable"] = dt;
    }
}
受保护的无效btn\u插入\u单击(对象发送方,事件参数e)
if(string.IsNullOrWhiteSpace(txt_productname.Text)| | string.IsNullOrWhiteSpace(txt_quantity.Text))
{
响应。写入(“警报('NotAllowNull')”;
}
其他的
{
数据表dt=null;
if(会话[“数据表”]!=null)
dt=(数据表)会话[“数据表”];
其他的
{
}
dt.Rows.Add(txt\u productname.SelectedValue.ToString());
dt.Rows.Add(txt_quantity.Text);
GridView1.DataSource=dt;
GridView1.DataBind();
会话[“数据表”]=dt;
}
}
错误:


中发生“System.NullReferenceException”类型的异常 安全管理System.dll,但未在用户代码中处理

其他信息:对象引用未设置为 反对


将断点应用于方法流,并逐步检查值设置为null的位置。如果代码中有空值,则会显示此错误消息。在回发方法上应用断点。检查数据表是否正确填写。或者您正在分配的值不为空。

“此错误”?什么错误?Security Management System.dll中发生“System.NullReferenceException”类型的异常,但未在用户代码中处理其他信息:对象引用未设置为对象的实例。您是否尝试单步执行代码并查找失败的位置?可能存在重复的