OdbcCommand cmdCombo = myConnection.CreateCommand();
OdbcCommand cmdList = myConnection.CreateCommand();
string myConnectionString = @"Driver={Microsoft Access Driver (*.mdb)};" + "Dbq=C:/DROPS-Data/Derrick.mdb";
{
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
//execute queries, etc
cmdCombo.CommandText = "SELECT * FROM DerrickAreas";
OdbcDataReader readerCombo = cmdCombo.ExecuteReader();
cmdCombo.CommandText = "SELECT * FROM DerrickAreas";
OdbcDataReader readerCombo = cmdCombo.ExecuteReader();
if (readerCombo.HasRows)
{
while (readerCombo.HasRows)
{
comboBox1.Items.Add(readerCombo["Section"].ToString());
readerCombo.NextResult();
}
}
else
{
MessageBox.Show("No records");
}
myConnection.Close();
{
while (readerCombo.HasRows)
{
comboBox1.Items.Add(readerCombo["Section"].ToString());
readerCombo.NextResult();
}
}
else
{
MessageBox.Show("No records");
}
myConnection.Close();
I am trying to populate the comboBox with data from Access database, which has 8 records, but it is showing only the first record
Can somebody point out the errors in this code
Ramesh PalanivelPosted Oct 16, 2017, 1:41 AM
Ramesh PalanivelPosted Oct 16, 2017, 1:52 AM
Rao VarreyPosted Oct 16, 2017, 1:48 AM
Rao VarreyPosted Oct 16, 2017, 1:34 AM
{
while (readerCombo.Read())
{
//comboBox1.Items.Add(readerCombo.GetValue("Section").ToString());
comboBox1.Items.Add(readerCombo.GetValue(1).ToString());
}
}
Ramesh PalanivelPosted Oct 16, 2017, 1:06 AM