通过访问文本框显示long Int

时间:2014-02-14 05:13:27

标签: c# telerik oledbdatareader

我想在文本框中填入在组合框中选择的客户名称的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);
        }
    }

1 个答案:

答案 0 :(得分: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);