473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

beginner update excel ?

I've been looking at working with Excel data.

I understand the process of getting the data into a dataset and modifying
it. It's one of simple beauty that is well documented. Now, I want to send
the updated data set back. I suspect this is also simple but it eludes me.

I have:
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Dim Conn As System.Data.Ole Db.OleDbConnect ion
Conn = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=" & FileName1 & ";" & _
"Extended Properties=Exce l 8.0;")
Dim da As New System.Data.Ole Db.OleDbDataAda pter("select * update ["
& sheetname1 & "]", Conn)
Try
Dim cmdbldr As New System.Data.Ole Db.OleDbCommand Builder(da)
da.UpdateComman d = cmdbldr.GetUpda teCommand
da.Update(DS)
Conn.Close()
Catch ex As System.Data.Ole Db.OleDbExcepti on
MsgBox(ex.Messa ge)
End Try
End Sub

Where ds is the dataset and sheetname1="she et1$".

This code throws the error: missing operator in querry expression
"update[sheet1$]". The code halts on the da.UpdateComman d line when the try
loop is disabled with an unhandled, unspecified
System.Data.Ole Db.OleDbExcepti on.

I suspect the problem is with the line:

Dim da As New System.Data.Ole Db.OleDbDataAda pter("select * update [" &
sheetname1 & "]", Conn)

Perhaps it is incomplete in some way.

I am sure I can loop all of the stuff in the data set back into the excel
sheet with explicit commands, specifying columns and values and all of that.
But how can I simply make the contents of the excel sheet mirror the changed
dataset (in the same simple way I make the dataset mirror the excel sheet to
begin with)??




--
mark b
Feb 14 '06 #1
5 4737
On Tue, 14 Feb 2006 13:24:26 -0800, "mark" <ma**@discussio ns.microsoft.co m> wrote:

¤ I've been looking at working with Excel data.
¤
¤ I understand the process of getting the data into a dataset and modifying
¤ it. It's one of simple beauty that is well documented. Now, I want to send
¤ the updated data set back. I suspect this is also simple but it eludes me.
¤
¤ I have:
¤ Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
¤ System.EventArg s) Handles Button3.Click
¤ Dim Conn As System.Data.Ole Db.OleDbConnect ion
¤ Conn = New System.Data.Ole Db.OleDbConnect ion( _
¤ "provider=Micro soft.Jet.OLEDB. 4.0; " & _
¤ "data source=" & FileName1 & ";" & _
¤ "Extended Properties=Exce l 8.0;")
¤ Dim da As New System.Data.Ole Db.OleDbDataAda pter("select * update ["
¤ & sheetname1 & "]", Conn)
¤ Try
¤ Dim cmdbldr As New System.Data.Ole Db.OleDbCommand Builder(da)
¤ da.UpdateComman d = cmdbldr.GetUpda teCommand
¤ da.Update(DS)
¤ Conn.Close()
¤ Catch ex As System.Data.Ole Db.OleDbExcepti on
¤ MsgBox(ex.Messa ge)
¤ End Try
¤ End Sub
¤
¤ Where ds is the dataset and sheetname1="she et1$".
¤
¤ This code throws the error: missing operator in querry expression
¤ "update[sheet1$]". The code halts on the da.UpdateComman d line when the try
¤ loop is disabled with an unhandled, unspecified
¤ System.Data.Ole Db.OleDbExcepti on.
¤
¤ I suspect the problem is with the line:
¤
¤ Dim da As New System.Data.Ole Db.OleDbDataAda pter("select * update [" &
¤ sheetname1 & "]", Conn)
¤
¤ Perhaps it is incomplete in some way.
¤
¤ I am sure I can loop all of the stuff in the data set back into the excel
¤ sheet with explicit commands, specifying columns and values and all of that.
¤ But how can I simply make the contents of the excel sheet mirror the changed
¤ dataset (in the same simple way I make the dataset mirror the excel sheet to
¤ begin with)??

See if the following helps:

How To Use ADO.NET to Retrieve and Modify Records in an Excel Workbook With Visual Basic .NET
http://support.microsoft.com/default...b;EN-US;316934
Paul
~~~~
Microsoft MVP (Visual Basic)
Feb 15 '06 #2
Yes, every thing seems to point to this type of explicit updating where
fields and records must be specified.

However, in Programming VB.NET by Balena (MS Press) in the Chapter 21 "ADO
in Disconnected Mode" pp 1097 et al, an update of the form
da.update(ds,"t ableName") appears. Yet, I cannot seem to make that work.

For example, I have code which reads an excel table into a a dataset(ds). A
grid is used to make modifications. I have verified that those modifications
have indeed occured in the dataset. but when I run the following:

Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
Dim Conn As System.Data.Ole Db.OleDbConnect ion
Conn = New System.Data.Ole Db.OleDbConnect ion( _
"provider=Micro soft.Jet.OLEDB. 4.0; " & _
"data source=" & FileName1 & ";" & _
"Extended Properties=Exce l 8.0;")
Conn.Open()

da = New System.Data.Ole Db.OleDbDataAda pter( _
"select * from [" & sheetname1 & "]",
OleDbConnection 1(CurrentIndex) )
Dim cmdbldr As New OleDbCommandBui lder(da)
da.InsertComman d = cmdbldr.GetInse rtCommand
da.DeleteComman d = cmdbldr.GetDele teCommand
da.UpdateComman d = cmdbldr.GetUpda teCommand
da.Update(DS, sheetname1)
Conn.Close()
End Sub

I get the error: The DataAdapter.Sel ectCommand.Conn ection property needs to
be initialized???

Feb 16 '06 #3
On Thu, 16 Feb 2006 11:07:32 -0800, "mark" <ma**@discussio ns.microsoft.co m> wrote:

¤ Yes, every thing seems to point to this type of explicit updating where
¤ fields and records must be specified.
¤
¤ However, in Programming VB.NET by Balena (MS Press) in the Chapter 21 "ADO
¤ in Disconnected Mode" pp 1097 et al, an update of the form
¤ da.update(ds,"t ableName") appears. Yet, I cannot seem to make that work.
¤
¤ For example, I have code which reads an excel table into a a dataset(ds). A
¤ grid is used to make modifications. I have verified that those modifications
¤ have indeed occured in the dataset. but when I run the following:
¤
¤ Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
¤ System.EventArg s) Handles Button3.Click
¤ Dim Conn As System.Data.Ole Db.OleDbConnect ion
¤ Conn = New System.Data.Ole Db.OleDbConnect ion( _
¤ "provider=Micro soft.Jet.OLEDB. 4.0; " & _
¤ "data source=" & FileName1 & ";" & _
¤ "Extended Properties=Exce l 8.0;")
¤ Conn.Open()
¤
¤ da = New System.Data.Ole Db.OleDbDataAda pter( _
¤ "select * from [" & sheetname1 & "]",
¤ OleDbConnection 1(CurrentIndex) )
¤ Dim cmdbldr As New OleDbCommandBui lder(da)
¤ da.InsertComman d = cmdbldr.GetInse rtCommand
¤ da.DeleteComman d = cmdbldr.GetDele teCommand
¤ da.UpdateComman d = cmdbldr.GetUpda teCommand
¤ da.Update(DS, sheetname1)
¤ Conn.Close()
¤ End Sub
¤
¤ I get the error: The DataAdapter.Sel ectCommand.Conn ection property needs to
¤ be initialized???

I don't see code for the DataAdapter's Fill method (on DS). Has it been omitted?
Paul
~~~~
Microsoft MVP (Visual Basic)
Feb 16 '06 #4

I created an original dataadaptor to fill the dataset in a previous sub.

Does my dataadaptor for the update need to be the same dataadaptor I used
for the original fill?
--
mark b
Feb 17 '06 #5
I changed my approach to using a single dataadaptor (da).

My update sub is:
Private Sub Update_Click(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles btn_Update.Clic k
DBCON.Open()
Dim cmdbldr As New OleDbCommandBui lder(da)
da.UpdateComman d = cmdbldr.GetUpda teCommand
da.Update(DS, sheetname1)
DBCON.Close()
End Sub

I now get the error:

Dynamic SQL generation for the DeleteCommand is not supported against a
SelectCommand that does not return any key column information. on the line:

da.UpdateComman d = cmdbldr.GetUpda teCommand

I suspect the problem is that Excel does not provide a primary key.


--
mark b
"Paul Clement" wrote:
On Thu, 16 Feb 2006 11:07:32 -0800, "mark" <ma**@discussio ns.microsoft.co m> wrote:

¤ Yes, every thing seems to point to this type of explicit updating where
¤ fields and records must be specified.
¤
¤ However, in Programming VB.NET by Balena (MS Press) in the Chapter 21 "ADO
¤ in Disconnected Mode" pp 1097 et al, an update of the form
¤ da.update(ds,"t ableName") appears. Yet, I cannot seem to make that work.
¤
¤ For example, I have code which reads an excel table into a a dataset(ds). A
¤ grid is used to make modifications. I have verified that those modifications
¤ have indeed occured in the dataset. but when I run the following:
¤
¤ Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
¤ System.EventArg s) Handles Button3.Click
¤ Dim Conn As System.Data.Ole Db.OleDbConnect ion
¤ Conn = New System.Data.Ole Db.OleDbConnect ion( _
¤ "provider=Micro soft.Jet.OLEDB. 4.0; " & _
¤ "data source=" & FileName1 & ";" & _
¤ "Extended Properties=Exce l 8.0;")
¤ Conn.Open()
¤
¤ da = New System.Data.Ole Db.OleDbDataAda pter( _
¤ "select * from [" & sheetname1 & "]",
¤ OleDbConnection 1(CurrentIndex) )
¤ Dim cmdbldr As New OleDbCommandBui lder(da)
¤ da.InsertComman d = cmdbldr.GetInse rtCommand
¤ da.DeleteComman d = cmdbldr.GetDele teCommand
¤ da.UpdateComman d = cmdbldr.GetUpda teCommand
¤ da.Update(DS, sheetname1)
¤ Conn.Close()
¤ End Sub
¤
¤ I get the error: The DataAdapter.Sel ectCommand.Conn ection property needs to
¤ be initialized???

I don't see code for the DataAdapter's Fill method (on DS). Has it been omitted?
Paul
~~~~
Microsoft MVP (Visual Basic)

Feb 17 '06 #6

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

Similar topics

12
22928
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL Server database that we have. Question follows: The following SQL statement, used in VBScript,
1
5290
by: jimserac | last post by:
The following SQL statement, used in VBScript, will COPY a table from Excel to an Access mdb. SQL = "SELECT * INTO C1R0" & _ " FROM IN ''" & _ " 'Excel 8.0;database=c:\excel\UpdateFinal1.xls';" What is the SQL statement that will UPDATE an already existing Access table
1
7550
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.
3
19721
by: JacksonYin | last post by:
1. I can fill data from Excel to DataSet like this: OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../../Book1.xls;Extended Properties=Excel 8.0;"); connection.Open(); OleDbCommand command =new OleDbCommand("SELECT * FROM myRange1", connection);
3
2333
by: Roy | last post by:
Hi Access gurus, I have a A2K application.The data in the database is updated daily by a excel download.I have a master n related tables keyed in by a OrderID.I have a problem in updating data.If it is a one to one update,i face no problem as I update every fields.But let's say if there is a master record with ID and three corresponding related entries for this on day 1.But on the next day,there was a change on related records 2 & 3 but...
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
6
43413
by: berndh | last post by:
Hi, I have a need to update all price fields in an SQL database. The new prices are in an excel spreadsheet (c:\db\update.xls). Unfortunately the structure of the Excel file is not the same as the SQL DB, as it is formatted for printing hardcopies and hence contains merged cells (purple) and formatting etc....(see excel.jpg) Also it uses different sheets as categories. The only real similarity that can be used is the ISBN number in...
2
7143
by: ruthboaz | last post by:
Hi, I am exporting a table with data to an excel file.. Some fields are empty in the exported file while the others and the key field, has values. The empty field(s) in excel, will be entered with values by another department. I require to update the access db from the updated excel fields to the respective fields in the database.. While using import from the file menu, I see that the information is append the table..
22
18131
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
8142
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
8642
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
8591
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
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5549
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
4058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
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
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.