Shaitan00 Posted August 21, 2005 Posted August 21, 2005 Given an EXCEL file [Tasks.xls] that has 2 worksheets [Tasks and Db]. The "Tasks" worksheet has multiple rows which are borken down into distinct columns [Name / Task / Start Time / Stop Time] I need to take each row of the Excel file [Tasks.xls] in the "Tasks" worksheet and populate my Datagrid [dgTasks]. Any clues? Any help would be much appreciated. Thanks, Quote
Diesel Posted August 21, 2005 Posted August 21, 2005 Are you looking for the code itself or a process? One process would be to create a datatable with the exact columns of the excel sheet. Read each column from the excel sheet and add the data to the appropriate column. Bind the datatable to the datagrid. Quote
Shaitan00 Posted August 21, 2005 Author Posted August 21, 2005 Okay - that seems simple enough besides one thing... How do I connect/read information from my EXCEL file? (specifically how do I make the datatable?) Quote
Joe Mamma Posted August 21, 2005 Posted August 21, 2005 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskcodeexamplereadingexceldataintodataset.asp Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Shaitan00 Posted August 21, 2005 Author Posted August 21, 2005 Nice - but is there an example in C# and not VB? Looking around the MSDN and can't find an equivalent C# version - and I doubt I can just convert it that simply. Quote
Diesel Posted August 22, 2005 Posted August 22, 2005 using System.Data; using System.Data.OleDb; DataSet DS; OleDbDataAdapter MyCommand; OleDbConnection MyConnection; MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source=C:\myData.XLS; Extended Properties=Excel 8.0;"); // Select the data from Sheet1 of the workbook. MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [sheet1$]", MyConnection); DS = new DataSet(); MyCommand.Fill(DS); MyConnection.Close(); Quote
Shaitan00 Posted September 5, 2005 Author Posted September 5, 2005 Okay - seriouslly that works great (100%) for READING values from the EXCEL database, now the problem I am having (and assumed it would be simple) is WRITING to the database... specifically, the EXCEL (.xls) file (worksheet = Sheet1) looks the like the following (using spaces to seperate the columns): row(1): Client1 Assignment1 RUNNING row(2): Client1 Assignment2 PAUSED row(3): Client2 Assignment1 FINISHED so I added the following lines of code: string sBlank = ""; MyCommand = new System.Data.OleDb.OleDbDataAdapter(insert into [ClientTaskTimer$] ([CLIENTS], [ASSIGNMENTS], [sTATUS]) values( '" + cbClient.Text + "', '" + cbAssignment.Text + "', '" + sBlank + "')", MyConnection); See the thing is I am not getting any errors - it just isn't WRITING to my EXCEL file and I got no clue why, is there something else I need to do, like commit the changes or something?.... help please... 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.