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>
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>