473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Update excel file with oledb

msjonathan
Hej hej,

I am trying to write an SQL update statement where I want to update an Excel file. But my Update statement is not valid, I have to use set .... But I do not know the columns in the Excel file, those can be different each time.
First I read an excel file with this code: http://codehill.com/2009/01/reading-...s-using-oledb/

I change some things in the DataTable and then I want to write to a copy of the first excel file.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  OleDbConnection con;
  3.  
  4.          if (isOpenXMLFormat)
  5.             //read a 2007 file  
  6.             ConnectionsString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
  7.                  pFileName + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
  8.          else
  9.             //read a 97-2003 file  
  10.             ConnectionsString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
  11.                 pFileName + ";Extended Properties=Excel 8.0;";
  12.          con = new OleDbConnection(ConnectionsString);
  13.  
  14.          OleDbDataAdapter cmd;
  15.          cmd = new OleDbDataAdapter("Update * [" + pWorksheetName + "$]", con);
  16.          con.Open();
  17.          cmd.Update(pData);
  18.          con.Close();
  19.  
  20.  
Has anyone an idea how to solve this?
EDIT: I posted this already but they advised to post it under ASP.NET

Greetz Jonathan
Jan 29 '10 #1
4 10616
Frinavale
9,735 Expert Mod 8TB
No where in this question is there anything related to ASP.NET?

I'm sorry but what type of application are you developing? An ASP.NET application/website? A windows desktop application?


Anyways, it would help if you posted the error message that you're getting.

Have you tried something like....
Expand|Select|Wrap|Line Numbers
  1.     String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("~/Temp/Book1.xls;")+Extended Properties='Excel 8.0;HDR=NO'";
  2.         OleDbConnection objConn = new OleDbConnection(sConnectionString);
  3.         objConn.Open();
  4.         OleDbCommand objCmdSelect = new OleDbCommand("UPDATE [Sheet1$A2:A2] SET F1=123456", objConn);
  5.         objCmdSelect.ExecuteNonQuery();
  6.         objCmdSelect = new OleDbCommand("UPDATE [Sheet1$A4:A4] SET F1='hello'", objConn);
  7.         objCmdSelect.ExecuteNonQuery();
  8.         objCmdSelect = new OleDbCommand("UPDATE [Sheet1$A5:A5] SET F1='goodby'", objConn); 
  9.         objCmdSelect.ExecuteNonQuery();
  10.  
-Frinny
Feb 1 '10 #2
I am using c#, somebody advised me to post it under asp.net first I posted it under SQL.
I retrieve a dataset from an excel file, do something with the data, add columns.
My problem is I can't write a normal update statement because it should update different excel files (the excel file defined by the user).
I am looking for a dynamic update statement, that updates all rows that are filled.
Or does anybody now how to write a dynamic insert statement?

Thanks in advance,

Jonathan
Feb 2 '10 #3
Curtis Rutland
3,256 Expert 2GB
I've moved this threat to the General .NET forum. I think it's a better place for it.

--insertAlias
MODERATOR
Feb 2 '10 #4
Curtis Rutland
3,256 Expert 2GB
Try using a OleDbCommandBuilder to generate your update statement.
Feb 2 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: vinay | last post by:
I have read the excel file into the datagrid and modified some data. Now i want to update the excel file with the data. How do I do it. Please help me.
1
by: Peter Cushing via .NET 247 | last post by:
I've an Excel file that I've been trying to make editable by Webusers via ASP.NET - however I just can't make the update syntaxto work. It's not an ASP problem, I've copied the code into anWindows...
0
by: cmay | last post by:
Problem: When impersonation is set in the web.config file, I cannot establish an OLEDB connection to the database from my ASP.NET v1.1 application. (Unspecified Error. Stack trace shows it...
4
by: Phoebe. | last post by:
Hi, Good Day! Reading 1 excel file into a dataset is fine. How can I read multiple excel with the same data structure into 1 dataset? How can I append those data? Can someone help? Thanks in...
1
by: Moomin Ma | last post by:
I have create a excel file with 2 columns and 2 rows for demonstration. The excel file is then opened by ms access and therefore a mdb file was created. The mdb file showing the correct linkage...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
1
by: Muskito | last post by:
HELP!!! Hello All, I'm using VB.net 2003 and trying to update data in Excel worksheet. The program selects data from the excel, updates something in the MSSQL DB and then tries to update...
0
by: qfchen | last post by:
I try to import data from an excel file, then save the data to a database, however, some cell always empty when read, whose cell combine with digit and alphabet, eg. "92FE0". below are the VB code ...
1
by: farnena | last post by:
I want to create a excel file every month and update details on certain events in a web application. 1. I dunno how to create Excel file in Web environment. 2. When I was trying to update the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.