kvnsdr
asked on
ComboBoxes loaded by multiple SQL query?
In an attempt to eliminate much C# code, I would like to make the following code work.
It compiles fine but errors upon inital loading to run. It errors by reading the second ComboBox in the While statement.
I've combined SQL statements in C# elsewhere if I place a ; between the SQL syntax.....
private void LoadComboBoxes()
{
string SQL = " SELECT DISTINCT datetime FROM TimeClock ORDER BY datetime ASC ; " +
" SELECT DISTINCT namefirst FROM TimeClock ORDER BY namefirst ASC ; " +
" SELECT DISTINCT namelast FROM TimeClock ORDER BY namelast ASC " ;
cn = new SqlConnection((Configurati onSettings .AppSettin gs["cn"]);
SqlDataAdapter da = new SqlDataAdapter(SQL,cn);
cn.Open();
SqlDataReader rdr = da.SelectCommand.ExecuteRe ader();
While(rdr.Read())
{
cbxDateTime.Items.Add(rdr[ "datetime" ].ToString ());
cbxNameFirst.Items.Add(rdr ["namefirs t"].ToStri ng()); // ERROR
cbxNameLast.Items.Add(rdr[ "namelast" ].ToString ());
}
rdr.Close();
cn.Close();
It compiles fine but errors upon inital loading to run. It errors by reading the second ComboBox in the While statement.
I've combined SQL statements in C# elsewhere if I place a ; between the SQL syntax.....
private void LoadComboBoxes()
{
string SQL = " SELECT DISTINCT datetime FROM TimeClock ORDER BY datetime ASC ; " +
" SELECT DISTINCT namefirst FROM TimeClock ORDER BY namefirst ASC ; " +
" SELECT DISTINCT namelast FROM TimeClock ORDER BY namelast ASC " ;
cn = new SqlConnection((Configurati
SqlDataAdapter da = new SqlDataAdapter(SQL,cn);
cn.Open();
SqlDataReader rdr = da.SelectCommand.ExecuteRe
While(rdr.Read())
{
cbxDateTime.Items.Add(rdr[
cbxNameFirst.Items.Add(rdr
cbxNameLast.Items.Add(rdr[
}
rdr.Close();
cn.Close();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much......