Hi, I have excel like this
and I want to select disctint on Column 2, and I want result return as below
I used the following code, but it only return value on column 2 which is only country
string strConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" +"Data Source = " + lblPath.Text.ToString() + "; Extended Properties = 'Excel 12.0;HDR=Yes;IMEX=1'"; using (OleDbConnection excelConnection = new OleDbConnection(strConnection)) { string strTable = Convert.ToString(comboBoxSelectTable.Text); string strSQL = "SELECT DISTINCT([Column 2]) FROM [Sheet1$]"; using (OleDbCommand dbCommand = new OleDbCommand(strSQL, excelConnection)) { using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(dbCommand)) { try { excelConnection.Open(); dataAdapter.Fill(dTable); dataGridView1.DataSource = dTable; } catch (Exception) { throw new Exception(ex.ToString()); } finally { dTable.Dispose(); dataAdapter.Dispose(); dbCommand.Dispose(); } } }
Thank in advance,