Adding Value to ComboBox from Excel using Winform C#

With Below attached Excel Used Excel

   //Establish a Connection
            string XlxPath = @"C:\Users\BreakIn\Documents\Visual Studio 2010\Projects\Test\TestData\Test Data.xlsx";
            string XlxPathCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + XlxPath + ";Extended Properties=Excel 8.0;HDR=Yes'";
            OleDbCommand MyDataAdp = new OleDbCommand();
            OleDbConnection Xlxconn = new OleDbConnection(XlxPathCon);
            MyDataAdp.Connection = Xlxconn;

          //  Accessing Sheets
            Xlxconn.Open();
            DataTable xdt;
            // Get all Sheets in Excel File
            xdt = Xlxconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            Xlxconn.Close();

            DataSet ds = new DataSet();
            String SheetName = xdt.Rows[0]["TABLE_NAME"].ToString();
            MyDataAdp.CommandText = "SELECT Test From[" + SheetName + "]";

            OleDbDataAdapter da = new OleDbDataAdapter(MyDataAdp);
            da.SelectCommand = MyDataAdp;
            da.Fill(ds);

            Testdes.Items.Clear();
            foreach (DataRow value in xdt.Rows)

            {
                Testdes.DataSource = ds.Tables["SheetName"].Columns["test"];
                Testdes.Items.Add(value["test"]);
            }
           Testdes.SelectedIndex = 0;
        }
    }
}

}

where "Testdes" is combobox.

How to get the values present in excel in specific Rows for Column "C" into ComboBox.

Answers


Are you sure there are no errors? It looks like the beginning quotation mark of your extended properties is missing

";Extended Properties=Excel 8.0;HDR=Yes'";

should be:

";Extended Properties='Excel 8.0;HDR=Yes'";

Need Your Help

Matching First Alphanumeric Character skipping (The |An? )

python mysql regex

I have a list of artists, albums and tracks that I want to sort using the first letter of their respective name. The issue arrives when I want to ignore "The ", "A ", "An " and other various non-

Join won't do it, and sub query sucks, then what?

tsql sql-server-2008 query-optimization

first of all, sorry for the non descriptive title, I'm just too rushed so I couldn't come up with a better one.