N
Nofi
Hello,
I'm trying to fill my combobox per code, not with a DataSet because I
want to have an empty row in it and this wasn't possible when working
with a DataSet. The fill works fine, but when I set the value and
display member I get false values.
string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Dokumente und Einstellungen\KosiorekA\Eigene Dateien\VS2005
Projects\CromaRENT\CromaRENT-DB\CromaRENT-DB.mdb";
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(sConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand("select agtName
from agent", conn);
OleDbDataReader reader = cmd.ExecuteReader();
cb_mainAgent.Items.Add("");
while (reader.Read())
{
cb_mainAgent.Items.Add(reader[0].ToString());
cb_mainAgent.DisplayMember(reader[0].ToString());
}
OleDbCommand neu = new OleDbCommand("select agtid from
agent", conn);
OleDbDataReader reader1 = neu.ExecuteReader();
while (reader1.Read())
{
cb_mainAgent.Items.Add(reader1[0].ToString());
cb_mainAgent.ValueMember(reader1[0].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
Now, when I select an entry in the combobox I get always the same ID,
no matter which display member is selected. And it is always the last,
existing ID in my table, what should I change?
Thank you.
I'm trying to fill my combobox per code, not with a DataSet because I
want to have an empty row in it and this wasn't possible when working
with a DataSet. The fill works fine, but when I set the value and
display member I get false values.
string sConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Dokumente und Einstellungen\KosiorekA\Eigene Dateien\VS2005
Projects\CromaRENT\CromaRENT-DB\CromaRENT-DB.mdb";
OleDbConnection conn = null;
try
{
conn = new OleDbConnection(sConn);
conn.Open();
OleDbCommand cmd = new OleDbCommand("select agtName
from agent", conn);
OleDbDataReader reader = cmd.ExecuteReader();
cb_mainAgent.Items.Add("");
while (reader.Read())
{
cb_mainAgent.Items.Add(reader[0].ToString());
cb_mainAgent.DisplayMember(reader[0].ToString());
}
OleDbCommand neu = new OleDbCommand("select agtid from
agent", conn);
OleDbDataReader reader1 = neu.ExecuteReader();
while (reader1.Read())
{
cb_mainAgent.Items.Add(reader1[0].ToString());
cb_mainAgent.ValueMember(reader1[0].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
Now, when I select an entry in the combobox I get always the same ID,
no matter which display member is selected. And it is always the last,
existing ID in my table, what should I change?
Thank you.