ThienZ Posted March 11, 2005 Posted March 11, 2005 i want to fill data to a strongly typed dataset fom excel. if i fill this strongly typed dataset with a sheet which has more columns than the typed dataset, these extra columns are put on the end of the typed dataset. example : my strongly typed dataset has 3 columns : name, address, id the excel sheet has 5 columns : name, birthdate, phone, id, email if i do this : OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + @"Data Source=" + filename + ";Extended Properties=Excel 8.0;"); conn.Open(); OleDbCommand cmd = new OleDbCommand("SELECT * FROM [sheet1$]", conn); OleDbDataAdapter adapter = new OleDbDataAdapter(); adapter.SelectCommand = cmd; myDataSet mynewds = new myDataSet(); adapter.Fill(mynewds, "mytable"); conn.Close(); mynewds has these columns : nam, address, id, birthdate, phone, email. how can i fill my strongly typed dataset only with columns, which in my strongly typed dataset exist? thx Quote
ThienZ Posted March 11, 2005 Author Posted March 11, 2005 right now i'm using a dumb method that deletes the extra columns, but i'm sure that there are better ways public static void adjustDataTable(DataTable sampleDT, DataTable toadjustDT) { DataTable extracols = toadjustDT.Clone(); foreach(DataColumn col in sampleDT.Columns) extracols.Columns.Remove(col.ColumnName); foreach(DataColumn col in extracols.Columns) toadjustDT.Columns.Remove(col.ColumnName); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.