none
並未將物件參考設定為物件的執行個體 RRS feed

  • 问题

  •  public void PSBM()
        {

            string GetBC = DBHelper.ExecuteQuery("select SortCode from Sort where indexid=" + Convert.ToInt32(DropDownList1.SelectedValue));
            string GetMC = DBHelper.ExecuteQuery("select SortCode from Sort where indexid=" + Convert.ToInt32(DropDownList2.SelectedValue));
            string GetSC = DBHelper.ExecuteQuery("select SortCode from Sort where indexid=" + Convert.ToInt32(DropDownList3.SelectedValue));

            if ((GetBC != "") && (GetMC != ""))
            {
                string sqlPSBM = "select * from PSBM where BClass='" + GetBC + "' and MClass='" + GetMC + "' and SClass='" + GetSC + "'";
                DataTable dt = SQLOperate.GetTable(sqlPSBM);

                Equ_name.DataTextField = "ProductName";
                Equ_name.DataValueField = "Prod_NameCode";
                Equ_name.DataSource = dt.DefaultView;
                Equ_name.DataBind();
                DBHelper.SetDDLControlTipMsg(Equ_name);


                string sqlStandard = "select * from PSBM where BClass='" + GetBC + "' and MClass='" + GetMC + "' and SClass='" + GetSC + "' and Prod_NameCode='" + Equ_name.SelectedItem.Value + "'";
                DataTable sS = SQLOperate.GetTable(sqlStandard);

                Type_Size.DataTextField = "Standard";
                Type_Size.DataValueField = "StandardCode";
                Type_Size.DataSource = sS.DefaultView;
                Type_Size.DataBind();
                DBHelper.SetDDLControlTipMsg(Type_Size);


                string sqlBrand = "select * from PSBM where BClass='" + GetBC + "' and MClass='" + GetMC + "' and SClass='" + GetSC + "' and Prod_NameCode='" + Equ_name.SelectedItem.Value + "' and StandardCode='" + Type_Size.SelectedItem.Value + "'";
                DataTable sB = SQLOperate.GetTable(sqlBrand);

                Brand.DataTextField = "Brand";
                Brand.DataValueField = "BrandCode";
                Brand.DataSource = sB.DefaultView;
                Brand.DataBind();
                DBHelper.SetDDLControlTipMsg(Brand);


                string sqlMadeArea = "select * from PSBM where BClass='" + GetBC + "' and MClass='" + GetMC + "' and SClass='" + GetSC + "' and Prod_NameCode='" + Equ_name.SelectedItem.Value + "' and StandardCode='" + Type_Size.SelectedItem.Value + "' and BrandCode='" + Brand.SelectedItem.Value + "'";
                DataTable sM = SQLOperate.GetTable(sqlMadeArea);

                MadeArea.DataTextField = "MadeArea";
                MadeArea.DataValueField = "MadeAreaCode";
                MadeArea.DataSource = sM.DefaultView;
                MadeArea.DataBind();
                DBHelper.SetDDLControlTipMsg(MadeArea);
            }
                   

        }
    执行到这一句就抱错了,始终找不到原因。("string sqlStandard = "select * from PSBM where BClass='" + GetBC + "' and MClass='" + GetMC + "' and SClass='" + GetSC + "' and Prod_NameCode='" + Equ_name.SelectedItem.Value + "'";
    "),大伙帮忙看下。

    2011年9月27日 1:45

答案

  • 可以通过断点来检查一下哪个值为Null~  :) 。。我猜测也许是Equ_name.SelectedItem
    共同努力,共同提高
    kaedei#live.cn My BLOG
    2011年9月27日 2:33
  • dear

    只能设定断点检查有哪个变量是null,也很有可能是SQL语句错误,导致有SQL 变量为null


    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
    2011年9月28日 4:34
  • Hi Tommy,

    如果我没有想错的话这个错误就是"未将对象引用设置到对象的实例"这个错误.
    在你代码的出错行里面也只有Equ_name.SelectedItem可能出这个错.
    在这一行之后设一个断点然后看看Equ_name.SelectedItem是不是值为null. 如果是,再检查你的Equ_name控件相关的代码是否有问题.

    祝你快乐每一天,

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年9月28日 5:19
    版主

全部回复

  • 可以通过断点来检查一下哪个值为Null~  :) 。。我猜测也许是Equ_name.SelectedItem
    共同努力,共同提高
    kaedei#live.cn My BLOG
    2011年9月27日 2:33
  • dear

    只能设定断点检查有哪个变量是null,也很有可能是SQL语句错误,导致有SQL 变量为null


    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
    2011年9月28日 4:34
  • Hi Tommy,

    如果我没有想错的话这个错误就是"未将对象引用设置到对象的实例"这个错误.
    在你代码的出错行里面也只有Equ_name.SelectedItem可能出这个错.
    在这一行之后设一个断点然后看看Equ_name.SelectedItem是不是值为null. 如果是,再检查你的Equ_name控件相关的代码是否有问题.

    祝你快乐每一天,

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年9月28日 5:19
    版主