Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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,

Posted

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.

Posted

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.

Posted

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();

  • 2 weeks later...
Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...