Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

unable to cast object of type system.int32 to type system.string combobox fill from database

$
0
0

I get the 'unable to cast object of type system.int32 to type system.string' error message when I try to populate a combobox from a datatable. The data is an int type (used as an identity column) the class is called on form load.

void fillComboRef()
{
    string constring = @"Data Source=|DataDirectory|\LWADataBase.sdf";
    string Query = "select * from customersTBL ";
    SqlCeConnection conDataBase = new SqlCeConnection(constring);
    SqlCeCommand cmdDataBase = new SqlCeCommand(Query, conDataBase);
    SqlCeDataReader myReader;
    try
    {
        conDataBase.Open();
        myReader = cmdDataBase.ExecuteReader();

        while (myReader.Read())
        {
            string sRef = myReader.GetString(myReader.GetOrdinal("Reference"));

            comboRef.Items.Add(sRef);
        }

        //displays a system error message if a problem is found
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>