0

我想用组合框中选择的客户名称的 ID 填充文本框。我在 customerID 下收到错误说


'System.Data.Oledb.OledbDataReader' 的未知方法 'GetInt32(string)'


这是整个代码的副本

        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);
        }
    }
4

1 回答 1

1

根据msdn GetInt32(int index)采用从零开始的列序号

所以把你的代码string query = "select * from RoadRunnerDB.custo.....

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

GetString( int index)按照msdn所述使用:

string custID = rd.GetString(0);
于 2014-02-14T05:17:36.903 回答