Hi i work in visual studio 2015 with c# windows form
i need to assign default value with value 0 and text select to combox
but How can i do that ?
In windows form load i make
- var fileName = string.Format("{0}\\Book3105", Directory.GetCurrentDirectory());
- var connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0};Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;", fileName);
- OleDbConnection con = new OleDbConnection(connection);
- try
- {
- con.Open();
- str = "select * from [sheet2$]";
- com = new OleDbCommand(str, con);
- oledbda = new OleDbDataAdapter(com);
- ds = new DataSet();
- oledbda.Fill(ds, "[sheet2$]");
- con.Close();
- dt = ds.Tables["[sheet2$]"];
- int i = 0;
- for (i = 0; i <= dt.Rows.Count - 1; i++)
- {
- comboBox4.Items.Add(dt.Rows[i].ItemArray[1]);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
How to do that if possible

Ali ali186 pointsPosted Jan 24, 2017, 4:06 AM EST
ahmed salahRank #2,612 · 534 pointsPosted Jan 24, 2017, 4:24 AM EST
ahmed salahRank #2,612 · 534 pointsPosted Jan 24, 2017, 5:06 AM EST
Problem
Selected value to any item in combo box give me null why
Details
I work in windows form c# visual studio 2015
And i get data of combo box from excel sheet 2007
excel sheet have two column
MemberId represent value to combo box
MemberName represent text to combo box
var fileName = string.Format("{0}\\Book3105", Directory.GetCurrentDirectory()); var connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0};Mode=ReadWrite;Extended Properties=Excel 12.0 Xml;", fileName); OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + "D:\\Book3105.xlsx" + ";" + "Extended Properties=\"Excel 12.0;HDR=YES\""); OleDbConnection con = new OleDbConnection(connection); try { con.Open(); str = "select * from [sheet2$]"; com = new OleDbCommand(str, con); oledbda = new OleDbDataAdapter(com); ds = new DataSet(); oledbda.Fill(ds, "[sheet2$]"); con.Close(); dt = ds.Tables["[sheet2$]"]; int i = 0; for (i = 0; i { comboBox4.Items.Insert(0, "select member"); comboBox4.SelectedIndex = 0; comboBox4.Items.Add(dt.Rows[i].ItemArray[1]); } } catch (Exception ex) { MessageBox.Show(ex.Message); }When debug this line under button give me null
and message box show to me when select any item in combo box .
private void buttontest_Click(object sender, EventArgs e) { if(Convert.ToInt32(comboBox4.SelectedValue)==0) { MessageBox.Show("wrong value"); } }