0

我的表单上有 2 个组合框(在表单加载事件中)。表单加载后,第一个组合框从 select 语句中获取一个值。我想在我的第二个组合框中使用该值。这是我的代码:

第一个组合框 = cbDelivery

        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = "User Id=christob;Password=CHRISTOB;Host=poseidon;Pooling=true;Min Pool    Size=0;Max Pool Size=100;Connection Lifetime=0;Port=1522;Sid=GLODCD";

        conn.Open();

        string query;
        query = "select distinct dd.delivery_bay_code from dc_delivery dd, dc_grv dg where delivery_complete_datetime is null and dd.dc_delivery_id_no = dg.dc_delivery_id_no and dd.delivery_announce_datetime is null";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            cbDelivery.Items.Add(dr["delivery_bay_code"]);
        }
        dr.Close();
        conn.Close();

2de 组合框 = cbOrderNo

此组合框位于:

私人无效 cbDelivery_SelectedIndexChanged(对象发送者,EventArgs e)

因此,一旦我从第一个组合框中选择一个值,我的第二个组合框查询就必须填充第二个组合框。见代码:

        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = "User Id=christob;Password=CHRISTOB;Host=poseidon;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;Port=1522;Sid=GLODCD";
        conn.Open();
        string query1;
        query1 = "select distinct dg.order_no from dc_delivery dd, dc_grv dg where delivery_complete_datetime is null and dd.dc_delivery_id_no = dg.dc_delivery_id_no and dd.delivery_announce_datetime is null and dd.delivery_bay_code = " + cbDelivery.Text;
        OracleCommand cmd1 = new OracleCommand(query1, conn);
        OracleDataReader dr1 = cmd1.ExecuteReader();
        while (dr1.Read())
        {
            cbOderNo.Items.Add(dr1["order_no"]);

        }
        dr1.Close();
        conn.Close();

注意我在第二个 Select 查询中使用了 cbDelivery 组合框。

问题是:一旦我从第一个组合框中选择一个值,第二个组合框就会给出异常“”ORA-00904:“BAY1”:标识符无效。

请帮我解决这个问题或提出不同的方法。

提前致谢。

4

2 回答 2

0

固定的!!我就是这样做的:

private void populateDeliveryBayCodes()
    {
        conn.Open();
        string query;
        query = "select distinct dd.delivery_bay_code from dc_delivery dd, dc_grv dg where dd.delivery_complete_datetime is null and dd.dc_delivery_id_no = dg.dc_delivery_id_no and dd.delivery_announce_datetime is null";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            cbDelivery.Items.Add(dr["delivery_bay_code"]);
        }
        dr.Close();
        conn.Close();
    }

    private void populateOrderNumbers()
    {
        conn.Open();
        string query;
        query = "select distinct dg.order_no from dc_delivery dd, dc_grv dg where dd.delivery_complete_datetime is null and dd.dc_delivery_id_no = dg.dc_delivery_id_no and dd.delivery_announce_datetime is null and dd.delivery_bay_code ='" + cbDelivery.Text + "' order by order_no";
        OracleCommand cmd = new OracleCommand(query, conn);
        OracleDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            cbOderNo.Items.Add(dr["order_no"]);
        }
        dr.Close();
        conn.Close();
    }

private void frmBuiltPallet_Load(object sender, EventArgs e)
    {
        populateDeliveryBayCodes();
    {

private void cbDelivery_SelectedIndexChanged(object sender, EventArgs e)
    {
        populateOrderNumbers();
    }
于 2012-12-03T12:23:00.133 回答
0

可能是您使用 sql 或 oracle 的某些关键字作为列名或在某个无效位置进行查询。在这种情况下,这种类型的错误是可能的。我不确定这个解决方案。但至少我们可以尝试一次。这样我们就可以确定它是否正确?

于 2012-11-30T12:24:25.043 回答