ORA-01008:不是所有变量绑定(数据集)

本文关键字:绑定 数据集 变量 ORA-01008 | 更新日期: 2023-09-27 18:05:41

我将gridview与ADO.net绑定。在我的Gridview中,我为每列设置了一个过滤器。当gridview绑定时,它们在页面加载时首次初始化。在调试时,我的viewstates显示有正确的值,但它给了我那个错误。我的文本框(过滤器)中的所有文本都存储在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();
    }
}

ORA-01008:不是所有变量绑定(数据集)

我简化了您的代码并收到相同的错误。通过更改

可以纠正主要问题。
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];
}

您是否可以像

那样在绑定中添加:
cmd.Parameters.Add(":upp",....

Rgds