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