Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down List not adding all records from query 1

Status
Not open for further replies.

bdbmeag

Programmer
Oct 5, 2008
15
0
0
US
Hi,

I'm using C# in ASP.NET 3.5; developing in VS2008 in Vista.

The code below uses a query to add items to a drop down list. The query currently has 3 records, however, the code is only adding two records to the drop down list.

When I step through the code it only steps through the "while (dr.Read())" loop two times.

Any help appreciated.

Thanks!

- Bruce


<code>
private void LoadData_Dates()
{

DateTime dteDate;

OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=S:\\dev\\devbatch\\Mockup.accdb;"
+ "User Id=admin;password=";

try
{
using (myConnection)
{
myConnection.Open();

string txtSQL = "SELECT * FROM qryList_Dates ";

OleDbCommand cmd = new OleDbCommand(txtSQL, myConnection);
OleDbDataReader dr = cmd.ExecuteReader();

dr.Read();

while (dr.Read())
{
dteDate = dr.GetDateTime(0);
ddlstDate.Items.Add(dteDate.ToString("d"));
}

dr.Close();
}
}
catch (Exception err)
{
lblError.Text += "Error reading the database - Dates.";
lblError.Text += err.Message;
}
}

</code>
 
remove this line of code and see what happens:
Code:
dr.Read();
 
Thanks!

It's always nice to have an extra pair of eyes!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top