C# 你在追查正确的错误吗? public void comboboxLoad() { string conn3str = <Connection String >; string quer

C# 你在追查正确的错误吗? public void comboboxLoad() { string conn3str = <Connection String >; string quer,c#,combobox,oledb,C#,Combobox,Oledb,你在追查正确的错误吗? public void comboboxLoad() { string conn3str = <Connection String >; string query1 = "select NM from Table1 where REFVALUE=1 ; "; OleDbConnection conn3 = new OleDbConnection(conn3str);

你在追查正确的错误吗?
public void comboboxLoad()
      {
            string conn3str = <Connection String >;
            string query1 = "select NM from Table1 where REFVALUE=1 ; ";
            OleDbConnection conn3 = new OleDbConnection(conn3str);
            OleDbCommand tblRow1 = new OleDbCommand(query1, conn3);
            OleDbDataReader rdRow1;
            try
            {
                conn3.Open();
                lblConnState.Text = "Connection Successful";
                rdRow1 = tblRow1.ExecuteReader();
                while (rdRow1.Read())
                {
                    int colindx1 = rdRow1.GetOrdinal("NM");
                    string sItbl = rdRow1.GetString(colindx1);
                    CB1.Items.Add(sItbl);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error  " + ex);
            }
        }
private void CB1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string conn3str = <Connection String >;
            OleDbConnection conn3 = new OleDbConnection(conn3str); 
            conn3.Open();

            // Pass the selected value from CB1 (string) equal to Table1.NM (string)           
            string query1a = "select ID from Table1 where NM = '" + CB1.Text + "' ; ";
            OleDbCommand TabID = new OleDbCommand(query1a, conn3);
            int TabId2 = Convert.ToInt32(TabID.ExecuteScalar());
            // Pass the variable TabId2 (int) equal to Table2.ID (int)                       
            string query2 = "select STATUS from Table2 where ID = '" + TabId2 + "'; ";

            OleDbCommand tblRow2 = new OleDbCommand(query2, conn3);
            // OleDbDataReader rdTabID;
            // OleDbDataReader rdRow2;

            try
            {
                OleDbDataReader rdRow2 = TabID.ExecuteReader();
                OleDbDataReader rdTabID = tblRow2.ExecuteReader(); // ** Error points to this line **

                while (rdRow2.Read())
                {
                    int TabIdidx = rdTabID.GetOrdinal("ID");
                    string TabIDVal = rdTabID.GetString(TabIdidx);
// Pass reference ID to label on form
                    lblBTableID.Text = TabId2.ToString();

                    int colindx1 = rdRow2.GetOrdinal("STATUS"); 
                    string sIntVal = rdRow2.GetString(colindx1);
                    cmbLowLvl.Items.Add(sIntVal);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error  " + ex);
            }
        }
private void CB1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string conn3str = <Connection String >;
        OleDbConnection conn3 = new OleDbConnection(conn3str); 


        // Pass the selected value from CB1 (string) equal to Table1.NM (string) but return the int ID.

    OleDbCommand tblRow2 = new OleDbCommand("select ID from Table1 where NM=  '"+ CB1.Text +"' ;" , conn3);
    try
        {
        conn3.Open();
                string r2 = Convert.ToString(tblRow2.ExecuteScalar());
                MessageBox.Show(r2);
                lblBTableID.Text = "ID Code= " + r2;
                conn3.Close();
    }
        catch (Exception ex)
        {
            MessageBox.Show("Error  " + ex);
        }
    }