0

I want to fill the text box with the ID of the customer name that has been selected in a combo box. I am getting error under customerID saying


Unknown method 'GetInt32(string)'of 'System.Data.Oledb.OledbDataReader'


this is the copy of the whole code

        private void RadMultiColumnComboBox1SelectedIndexChanged(object sender, EventArgs e)
    {
        string constring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= RoadRunnerDB.mdb";
        string query = "select * from RoadRunnerDB.customerList where customerCompanyName = '" + radMultiColumnComboBox1 + "';";
        OleDbConnection con = new OleDbConnection(constring);
        OleDbCommand cmd = new OleDbCommand(query, con);            
        OleDbDataReader rd;
        try
        {
            con.Open();
            rd = cmd.ExecuteReader();

            while (rd.Read())
            {                             //Error is under here
                string custID = rd.GetInt32("customerID").ToString();
                radTextBox5.Text = custID;
            }
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
Pigeon
  • 117
  • 1
  • 13

1 Answers1

1

As per the msdn GetInt32(int index) takes zero-based column ordinal

so change you code from string query = "select * from RoadRunnerDB.custo..... to

string query = "select customerID from RoadRunnerDB.customerList.... 

and use GetString( int index) as msdn stated :

string custID = rd.GetString(0);
Mohammad Arshad Alam
  • 9,694
  • 6
  • 38
  • 61
  • yes!! it kind of worked. I am getting the customerName but not the ID or customerID. Going to try couple of things and report back. – Pigeon Feb 14 '14 at 13:05
  • I also changed my query to `string.Format("select customerCompanyName, customerID from customerList where customerCompanyName = '{0}'", radMultiColumnComboBox1.Text);` – Pigeon Feb 14 '14 at 13:12
  • `int custID = rd.GetInt32(1); string custID2 = custID.ToString(); radTextBox5.Text = custID2;` Now it is working Thank you sir. – Pigeon Feb 14 '14 at 13:20