Problem in Connecting Excel File
-
private bool Connect() { string DB_Path= @"E:\Office Project\salary project\AttendanceSummary.csv"; string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"; con = new OleDbConnection(Con_Str); con.Open(); string query = "SELECT SNO, ECODE, NAME, PRESENT, ABSENT, OFF, LEAVE, LWP, OTHOURS FROM [AttendanceSummary$]"; OleDbDataAdapter oda = new OleDbDataAdapter(query, con); DataSet ds = new DataSet(); oda.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.Update(); if (con.State == ConnectionState.Open) { MessageBox.Show("Connected"); return true; } else return false; } ====>>>> this code is working fine...........Problem is that when i am connecting other file "XYZ.XLS" which is having some text heading in the Top Rows................ its showing error ....... pls kindly help me Thanks in Advance.( sorry if any mistake i am very new to programming)
-
private bool Connect() { string DB_Path= @"E:\Office Project\salary project\AttendanceSummary.csv"; string Con_Str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_Path + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";"; con = new OleDbConnection(Con_Str); con.Open(); string query = "SELECT SNO, ECODE, NAME, PRESENT, ABSENT, OFF, LEAVE, LWP, OTHOURS FROM [AttendanceSummary$]"; OleDbDataAdapter oda = new OleDbDataAdapter(query, con); DataSet ds = new DataSet(); oda.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; dataGridView1.Update(); if (con.State == ConnectionState.Open) { MessageBox.Show("Connected"); return true; } else return false; } ====>>>> this code is working fine...........Problem is that when i am connecting other file "XYZ.XLS" which is having some text heading in the Top Rows................ its showing error ....... pls kindly help me Thanks in Advance.( sorry if any mistake i am very new to programming)