I'm newbie to C# so please bear with me for that issue and just to make the issue clear i'm gonna start from the very beginning of the My code What i wanted to do @ the beginning that i wanted to populate my comboBox from MS ACCESS database but with both a value to hold in the combobox and a value to display as the following : i wanted to populate the combobox with the Empolyer ID but make the combobox displaye the name as showen in the pic
public static void FillDropDownList(string Query, System.Windows.Forms.ComboBox DropDownName, string AValue, string Adisplay)
{
string Value = AValue;
string display = Adisplay;
using (var CONN = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\Vendors.accdb;"))
{
CONN.Open();
DataTable dt = new DataTable();
try
{
OleDbCommand cmd = new OleDbCommand(Query, CONN);
OleDbDataReader myReader = cmd.ExecuteReader();
dt.Load(myReader);
/// MessageBox.Show (dt.Rows.Count.ToString());
// Console.ReadLine();
}
catch (OleDbException e)
{
MessageBox.Show(e.ToString());
// Console.WriteLine(e.ToString());
// Console.ReadLine();
return;
}
DropDownName.DataSource = dt;
DropDownName.ValueMember = Value;
DropDownName.DisplayMember = display;
}
}
And i call it in the load like the following
private void VendorMain_Load(object sender, EventArgs e){FillDropDownList("select EMPCODE,EMPNAME from EMPLOYERS ", EMP_CB , "EMPCODE", "EMPNAME ");}
and i thought that everything worked perfectly until the point i wanted to only add the Value member in another table in the database so when i tried to added using the insert SQL statement i found that the value member that is being added is the text "EMPCODE" not the value of the code it self { 1 or 2 or 3 ,,,,,,, },so does any body have a solution for this ........ ???