private void btn_update_Click(object sender, EventArgs e) { for (int i = list_sheetnames.Items.Count -1; i >= 0; i--) { string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox_filename.Text + ";Extended Properties='Excel 12.0 XML;HDR=YES;';"; string selectCmd = "Select SUM(Total) As Total_SUM From [" + list_sheetnames.Items[i] + "$]"; using(OleDbConnection excelConn = new OleDbConnection(connString)) { excelConn.Open(); OleDbCommand command = new OleDbCommand(selectCmd, excelConn); OleDbDataAdapter da = new OleDbDataAdapter(command); DataTable sheetInfo = new DataTable(); da.Fill(sheetInfo); //Do something with the data. //list_total.Items.Add(sheetInfo); list_total.DataSource = da.ToString(); } }
List<string> lst = new List<string>(); foreach (DataRow r in sheetInfo.Rows) { string sheettotal = (string)r["Total_SUM"].ToString(); lst.Add(sheettotal); } list_total.DataSource = lst;
Quote: C# list_total.DataSource = da.ToString();
list_total.DataSource = da.ToString();
"System.Data.OleDb.OleDbDataAdapter"
list_total.DataSource = sheetInfo;
DisplayMember
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)