473,624 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Excel using ado.net - operation must use an updateable query

This is driving me nuts. I'm trying to update an Excel spreadsheet
using ADO.Net and Oledb in VB.Net. The connection is open, the
adapter is connected and the dataset is loaded. Here's the code in
question:

myDataRow = myDataSet.Table s(0).Rows(RowNu m)
myDataRow(Colum nCount) = Ailment
Adapter.UpdateC ommand = New OleDbCommand("U PDATE [" &
SheetName & "] SET F" & ColumnCount & " = '" & Ailment & "' where F1 =
" & RowNum & "", Conn)
Adapter.Update( myDataSet, "[" & SheetName & "]")
The query sent is:

"UPDATE [Drugs cleaned up$] SET F6 = 'Test Ailment' where F1 = 1"

In the spreadsheet, F1 = 1. It's a uniquely numbered column and I
assume, the primary key. F6 is also a valid column. The Sheet name
is also correct cause it's open. I figured, and am told from MS
documents, that a unique column is required to make it an updateable
query. That's what I've done but I can't get anything but:

"operation must use an updateable query"

Every article I find with a solution says it's a permissions issue
with ASP.Net. But this is VB.Net, everything running from a machine
with Administrator privs. The C drive and the file have Full Access
to Everyone and the sheet(s) are not protected.

Any ideas?
Thanks!

Nov 21 '05 #1
8 1414
I don't think you can update an Excel sheet using OLEDB (also a text file).
That's why yo get the message "operation must use an updateable query"

Venki

"Tom wilson" wrote:
This is driving me nuts. I'm trying to update an Excel spreadsheet
using ADO.Net and Oledb in VB.Net. The connection is open, the
adapter is connected and the dataset is loaded. Here's the code in
question:

myDataRow = myDataSet.Table s(0).Rows(RowNu m)
myDataRow(Colum nCount) = Ailment
Adapter.UpdateC ommand = New OleDbCommand("U PDATE [" &
SheetName & "] SET F" & ColumnCount & " = '" & Ailment & "' where F1 =
" & RowNum & "", Conn)
Adapter.Update( myDataSet, "[" & SheetName & "]")
The query sent is:

"UPDATE [Drugs cleaned up$] SET F6 = 'Test Ailment' where F1 = 1"

In the spreadsheet, F1 = 1. It's a uniquely numbered column and I
assume, the primary key. F6 is also a valid column. The Sheet name
is also correct cause it's open. I figured, and am told from MS
documents, that a unique column is required to make it an updateable
query. That's what I've done but I can't get anything but:

"operation must use an updateable query"

Every article I find with a solution says it's a permissions issue
with ASP.Net. But this is VB.Net, everything running from a machine
with Administrator privs. The C drive and the file have Full Access
to Everyone and the sheet(s) are not protected.

Any ideas?
Thanks!

Nov 21 '05 #2
> Any ideas?

Excel isn't a database. It makes a great presentation tier, if you
want to keep/update your DB and then output an Excel sheet.
Nov 21 '05 #3
"vvenk" <vv***@discussi ons.microsoft.c om> wrote ...
I don't think you can update an Excel sheet using OLEDB (also a text file).
That's why yo get the message "operation must use an updateable query"


You are mistaken: it is indeed possible to update an Excel sheets and
a text files using OLE DB.

Jamie.

--
Nov 21 '05 #4
Tom wilson <ye*******@nosp am.com> wrote ...
myDataRow = myDataSet.Table s(0).Rows(RowNu m)
myDataRow(Colum nCount) = Ailment
Adapter.UpdateC ommand = New OleDbCommand("U PDATE [" &
SheetName & "] SET F" & ColumnCount & " = '" & Ailment & "' where F1 =
" & RowNum & "", Conn)
Adapter.Update( myDataSet, "[" & SheetName & "]")
The query sent is:

"UPDATE [Drugs cleaned up$] SET F6 = 'Test Ailment' where F1 = 1"

In the spreadsheet, F1 = 1. It's a uniquely numbered column and I
assume, the primary key. F6 is also a valid column. The Sheet name
is also correct cause it's open. I figured, and am told from MS
documents, that a unique column is required to make it an updateable
query. That's what I've done but I can't get anything but:

"operation must use an updateable query"


You SQL works for me using this code:

Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source='C:\Temp o\db.xls';Exten ded Properties='Exc el 8.0;HDR=NO'"
Dim conn As New OleDbConnection (strConn)
Dim strSQL As String = "UPDATE [Drugs cleaned up$] SET F6 = 'Test
Ailment' where F1 = 1"
Dim cmd As New OleDbCommand(st rSQL)
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQ uery()
cmd.Connection. Close()

As regards the error you are getting, Jet doesn't like in an update
e.g.

UPDATE MyTable SET MyCol = (
SELECT Col1 FROM OneRowTable
);

The above fails with the same error as your even thought the table in
the subquery isn't itself being updated. I'm wondering if one of your
..NET objects is using additional SQL under the covers that is
upsetting the provider. My code, on the other hand, simply sends the
SQL unaltered to the provider for execution. Just a guess.

Jamie.

--
Nov 21 '05 #5
On 22 Nov 2004 01:43:55 -0800, ja**********@xs mail.com (Jamie Collins) wrote:

¤ "vvenk" <vv***@discussi ons.microsoft.c om> wrote ...
¤
¤ > I don't think you can update an Excel sheet using OLEDB (also a text file).
¤ > That's why yo get the message "operation must use an updateable query"
¤
¤ You are mistaken: it is indeed possible to update an Excel sheets and
¤ a text files using OLE DB.
¤
¤ Jamie.

Actually that's half right. You can update data in Excel Worksheets but the Text ISAM driver does
not support the capability to update data in a text file.
Paul ~~~ pc******@amerit ech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #6
THANKS!!!!

I'm given a spreadsheet where any one of the columns can contain a
list of drug names. I have an Access database with a massive list of
drug names and the ailments those drugs treat. I'm to insert a new
column in the spreadsheet, lookup the drug and populate a new appended
column with the referenced ailment. That's why I have to 'modify' an
Excel SS. (That should answer Slugg's q)

However, if I can't get the code you supplied to work directly I'll
first import the SS data into an Access table (I can read the SS all I
want no problem) , do the lookups and the rest of the work within the
Access table and then write it out to a brand new .xls file. (I can
write new stuff all I want, just not modify)

Thank you very much for the input, any advice on this topic is
non-existent and has been frustrating to find. I'll try your example
and expand from there.

Tom
On 22 Nov 2004 01:45:41 -0800, ja**********@xs mail.com (Jamie Collins)
wrote:
Tom wilson <ye*******@nosp am.com> wrote ...
myDataRow = myDataSet.Table s(0).Rows(RowNu m)
myDataRow(Colum nCount) = Ailment
Adapter.UpdateC ommand = New OleDbCommand("U PDATE [" &
SheetName & "] SET F" & ColumnCount & " = '" & Ailment & "' where F1 =
" & RowNum & "", Conn)
Adapter.Update( myDataSet, "[" & SheetName & "]")
The query sent is:

"UPDATE [Drugs cleaned up$] SET F6 = 'Test Ailment' where F1 = 1"

In the spreadsheet, F1 = 1. It's a uniquely numbered column and I
assume, the primary key. F6 is also a valid column. The Sheet name
is also correct cause it's open. I figured, and am told from MS
documents, that a unique column is required to make it an updateable
query. That's what I've done but I can't get anything but:

"operation must use an updateable query"


You SQL works for me using this code:

Dim strConn As String = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source='C:\Tem po\db.xls';Exte nded Properties='Exc el 8.0;HDR=NO'"
Dim conn As New OleDbConnection (strConn)
Dim strSQL As String = "UPDATE [Drugs cleaned up$] SET F6 = 'Test
Ailment' where F1 = 1"
Dim cmd As New OleDbCommand(st rSQL)
cmd.Connection = conn
conn.Open()
cmd.ExecuteNonQ uery()
cmd.Connection. Close()

As regards the error you are getting, Jet doesn't like in an update
e.g.

UPDATE MyTable SET MyCol = (
SELECT Col1 FROM OneRowTable
);

The above fails with the same error as your even thought the table in
the subquery isn't itself being updated. I'm wondering if one of your
.NET objects is using additional SQL under the covers that is
upsetting the provider. My code, on the other hand, simply sends the
SQL unaltered to the provider for execution. Just a guess.

Jamie.


Nov 21 '05 #7
Paul Clement <Us************ ***********@sws pectrum.com> wrote ...
¤ it is indeed possible to update an Excel sheets and
¤ a text files using OLE DB.

Actually that's half right. You can update data in Excel Worksheets but the
Text ISAM driver does
not support the capability to update data in a text file.


Yes, I admit I was half wrong. I was thinking of INSERT INTO which is
supported for Text. Apologies to vvenk.

Jamie.

--
Nov 21 '05 #8
Tom wilson <ye*******@nosp am.com> wrote ...
I'm given a spreadsheet where any one of the columns can contain a
list of drug names. I have an Access database with a massive list of
drug names and the ailments those drugs treat. I'm to insert a new
column in the spreadsheet, lookup the drug and populate a new appended
column with the referenced ailment. That's why I have to 'modify' an
Excel SS. (That should answer Slugg's q)
Rather than updating data, you are talking about altering the
worksheet's *schema* i.e.

ALTER TABLE ['Drugs cleaned up$'] ADD MyNewCol FLOAT NULL;

This is not supported for Excel. However, because you are using a
worksheet rather than a 'named range' (workbook level defined Name),
there is a workaround: if you put HDR=NO (no column header row) in the
extended properties of the connection string, you can add a new column
header e.g. say you already have column headers in range A1:C1 so the
new column header goes in D1:

UPDATE [Drugs cleaned up$D1:D1] SET F1='MyNewCol';

That said, you may well not be using headers at all which makes things
a bit tricky. While you can specify the address of the range to query,
you will only get columns and data rows for those the intersection
between the address specified and the UsedRange e.g.

SELECT * FROM [Drugs cleaned up$A1:D65535];

may only return, say, three columns if column D had not contained
data.

Another workaround is to use SELECT..INTO to create a new temp table
in your Jet (MS Access) database:

SELECT *
INTO [MS Access;Database =C:\MyDB.mdb;].NewTempTable
FROM ['Drugs cleaned up$'];

and you could additionally do any JOINs to get your final result set
at the same time, then DROP the Excel table:

DROP TABLE ['Drugs cleaned up$'];

then export the temp table back to Excel:

SELECT *
INTO [Drugs cleaned up]
FROM [MS Access;Database =C:\MyDB.mdb;].NewTempTable;

although when I tested this just now, because you sheet name includes
space characters, the new Excel table was created on a new sheet named
Drugs_cleaned_u p.
Thank you very much for the input, any advice on this topic is
non-existent and has been frustrating to find.


I agree. Most of what I've gleaned comes from these newsgroups and
practical experimentation . There is little info on MSDN e.g. I have
yet to find the Jet 4.0 help files (Jet 3 help is there). Post back if
you need further help (I even used to develop hospital prescribing
software but I longer have the required multi-million dollar insurance
cover <g>).

Jamie.

--
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
902
by: Tom wilson | last post by:
This is driving me nuts. I'm trying to update an Excel spreadsheet using ADO.Net and Oledb in VB.Net. The connection is open, the adapter is connected and the dataset is loaded. Here's the code in question: myDataRow = myDataSet.Tables(0).Rows(RowNum) myDataRow(ColumnCount) = Ailment Adapter.UpdateCommand = New OleDbCommand("UPDATE SET F" & ColumnCount & " = '" & Ailment & "' where F1 = " & RowNum & "", Conn)...
4
3893
by: Mark | last post by:
I am reading from an excel spreadsheet as an ODBC Recordset. But whenever i try to write to it I get an error A) Ideally i would like to write "Mark" to A5 like this : RS("$A5") = "Mark" RS.UpdateBatch but it doenst like the RS("$A5") is there an easy way to do this?
2
7508
by: SheryMich | last post by:
Hi - I am having a bit of a problem with the insert into a database. When I go to insert a record into an un-keyed, single table Access database, I get the aforementioned ''Operation Must Use an Updateable Query' error. Points: - The database is in my local temp directory, not inetpub - The directory has read/write permissions - The database has read/write permissions - I created another version of the dbase and tried to reference it...
1
3574
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 something back to the excel worksheet. My problem is that i'm having this annoying exception: "Operation must
11
3947
by: Arpan | last post by:
I have always been working with SQL Server 2005 for ASP.NET apps but due to some reasons, had to revert back to MS-Access 2000. When I try to insert/update a MS-Access DB table (MDB), ASP.NET generates the following error: Operation must use an updateable query. pointing to a line that says
10
2912
by: Ben | last post by:
Hi, i have a weird problem and i don't know who is responsible for this: IIS, excel or asp.net. My problem: we use an asp.net 2.0 application under IIS 6.0 (server 2003 sp2) which must write data from a form into a table in excel files (i know excel is not really recommended for that, but it's excel).There are a lot of excel files, all in the same directory with the same privileges (Network service has
1
1845
by: nerd19 | last post by:
hi, im trying to do an update query that will take 2fields from 3 excel tables through a union query, BulkUpdate then update an access table, Tools, with the new information. I have done a similar process but with an add query which works fine, this one is just goin to update old information if it already exists. Here is my sql code for the queries: Importing from excel, BulkImport union query- SELECT . AS , . AS FROM WHERE ((.) Is...
1
5298
by: tommydnp | last post by:
Is there a possibility to insert values into excel using only an oledb connection? It's no problem for me to select all data, but when I want to insert data or create a table, there's a problem. When I want to insert I always get: "Operation must use an updateable query". When I want to create a table I get a message that it's a read-only database. sql.CommandText = "insert into (, ) values('1', '2')"
1
2749
by: pavya | last post by:
Hi, I have developed one Web application. At that time my system had a FAT file system on it and this application worked properly. But now i have converted FAT file system to NTFS file system and whenever i am trying to run this application then it through the exception. I have used MS Access as a database. The error is as follows... Server Error in '/ASG' Application....
0
8236
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8173
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8679
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8621
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7159
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2606
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.