ORA-01008:并非所有变量都绑定(数据集)

时间:2015-07-30 06:23:44

标签: c# asp.net oracle gridview

我将我的gridview绑定到ADO.net。在我的Gridview中,每列都有一个过滤器。当gridview绑定时,它们首次在页面加载中初始化。在调试时,我的视图状态显示具有正确的值,但它给了我该错误。我的文本框(过滤器)中的所有文本都存储在Viewstate中。

这是我的代码。

 protected void Page_Load(object sender, EventArgs e)
{

    if (!IsPostBack)
    {
        Initialize();
        GridViewPlanning_Bind("like '%'");
    }
}

private void Initialize()
{
    ViewState["txtUnloadingPlaceSearch"] = "";
    ViewState["txtAutoTypeSearch"] = "";
    ViewState["txtExpeditionHouseSearch"] = "";
    ViewState["txtDeliveryConditionSearch"] = "";
    ViewState["txtTransporterNameSearch"] = "";       
    ViewState["txtDateLoadingSearch"] = "";
    ViewState["txtDateUnloadSearch"] = "";
    ViewState["txtCarNumberSearch"] = "";
    ViewState["DateLoadFirst"] = "0";
    ViewState["DateLoadLast"] = "32535208799000";
    ViewState["DateUnloadFirst"] = "0";
    ViewState["DateUnloadLast"] = "32535208799000";
    ViewState["DateLoadF"] = "";
    ViewState["DateLoadL"] = "";
    ViewState["DateUnloadF"] = "";
    ViewState["DateUnloadL"] = "";
}

private void GridViewPlanning_Bind(string sw)
{
    string select_sql_Planning_GW = "SELECT P.ID, " +
                          "P.DATE_LOADING," +
                          "UNLOAD.PLACE, " +
                          "P.DATE_UNLOAD," +
                          "AT.AUTO," +
                          "P.NUMBER," +
                          "EXPEDITION.NAME_EH," +
                          "DELIVERY.CONDITION," +
                          "NAME.NAME_T," +
                          "P.ID_PLACE," +
                          "P.ID_AUTO," +
                          "P.ID_EXPEDITION_HOUSE," +
                          "P.ID_DELIVERY_CONDITION," +
                          "P.ID_NAME," +
                          "P.STATUSP " +
                            "FROM UNLOAD " +
                            "RIGHT JOIN P " +
                            "ON UNLOAD.ID = P.ID_PLACE " +
                            "LEFT JOIN AT " +
                            "ON P.ID_AUTO = AT.ID " +
                            "LEFT JOIN EXPEDITION " +
                            "ON P.ID_EXPEDITION_HOUSE = EXPEDITION.ID " +
                            "LEFT JOIN DELIVERY " +
                            "ON P.ID_DELIVERY_CONDITION = DELIVERY.ID " +
                            "LEFT JOIN NAME " +
                           " ON P.ID_NAME = NAME.ID " +
                           " WHERE STATUSP " + sw +
                           "  AND lower(UNLOAD.PLACE) LIKE :upp" +
                            " AND lower(AT_AUTO) LIKE :att" +
                            " AND lower(EXPEDITION.NAME_EH) LIKE :ehh" +
                            " AND lower(DELIVERY.CONDITION) LIKE :dcc" +
                             " AND lower(NAME.NAME_T) LIKE :ntt" +
                             " AND lower(P.DATE_LOADING) BETWEEN :date_firstt and :date_lastt" +
                             " AND lower(P.DATE_UNLOAD) BETWEEN :dateu_firstt and :dateu_lastt" +
                             " AND lower(P.NUMBER) LIKE :ncc " +
                           " ORDER BY PLANNING.ID ASC ";

    using (OracleConnection con = new OracleConnection(ConfigurationManager.ConnectionStrings["DBCS"].ToString()))
    {
        con.Open();
        OracleCommand cmd = new OracleCommand(select_sql_Planning_GW, con);
        OracleDataAdapter adapter = new OracleDataAdapter(select_sql_Planning_GW, con);
        DataSet dss = new DataSet();         
        cmd.Parameters.Add("upp", "%" + ViewState["txtUnloadingPlaceSearch"].ToString().ToLower() + "%");
        cmd.Parameters.Add("att", "%" + ViewState["txtAutoTypeSearch"].ToString().ToLower() + "%");
        cmd.Parameters.Add("ehh", "%" + ViewState["txtExpeditionHouseSearch"].ToString().ToLower() + "%");
        cmd.Parameters.Add("dcc", "%" + ViewState["txtDeliveryConditionSearch"].ToString().ToLower() + "%");
        cmd.Parameters.Add("ntt", "%" + ViewState["txtTransporterNameSearch"].ToString().ToLower() + "%");
        cmd.Parameters.Add("date_firstt", ViewState["DateLoadFirst"]);
        cmd.Parameters.Add("date_lastt", ViewState["DateLoadLast"]);
        cmd.Parameters.Add("dateu_firstt", ViewState["DateUnloadFirst"]);
        cmd.Parameters.Add("dateu_lastt", ViewState["DateUnloadLast"]);
        cmd.Parameters.Add("ncc", "%" + ViewState["txtCarNumberSearch"].ToString().ToLower() + "%");

        adapter.Fill(dss);  // this is where I have the error
        GridViewPlanning.DataSource = dss;
        GridViewPlanning.DataBind();
    }
}

2 个答案:

答案 0 :(得分:1)

我简化了您的代码并收到了同样的错误。通过改变来纠正主要问题:

OracleDataAdapter adapter = new OracleDataAdapter(select_sql_Planning_GW, con);  

为:

OracleDataAdapter adapter = new OracleDataAdapter(cmd);

我不确定您是否需要进行任何其他更改,无论如何这里是整个代码,对我有用:

Dictionary<string, string> ViewState = new Dictionary<string, string>();
ViewState.Add("txtUnloadingPlaceSearch", "");

string select_sql_Planning_GW = "SELECT dummy from dual where upper(dummy) LIKE :upp ";

using (OracleConnection con = new OracleConnection(connectionString))
{
    con.Open();
    OracleCommand cmd = new OracleCommand(select_sql_Planning_GW, con);
    cmd.Parameters.AddWithValue("upp", 
        "%" + ViewState["txtUnloadingPlaceSearch"].ToString().ToLower() + "%");
    OracleDataAdapter adapter = new OracleDataAdapter(cmd);
    DataSet dss = new DataSet();

    adapter.Fill(dss);
    GridViewPlanning.DataSource = dss.Tables[0];
}

希望这有帮助。

答案 1 :(得分:0)

你可以在你的绑定中添加:

cmd.Parameters.Add(":upp",....

RGDS