473,383 Members | 1,801 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,383 software developers and data experts.

Cannot update 1 of 2 tables - Dynamic SQL generation is not supported

Hi, I'm having a problem with my code,

I am doing the following - retrieving a field from a table, which is linked to another table, i'm only updating one of the fields in one of the two tables...


Expand|Select|Wrap|Line Numbers
  1.          ##############
  2.  
  3.       Page Load Sub
  4.  
  5.  
  6.       sqlselect = "Select ProductID,Name,Price from Products,Store Where Products.StoreID = Store.StoreID And StoreID = 7"
  7.  
  8.       connectionstring = dh.returnconnection # returns the connection string to the location of the database
  9.  
  10.  
  11.       sqlcon = new sqlconnection(connectionstring)
  12.  
  13.       da = new sqlDataAdapter(sqlselect,connectionstring)
  14.  
  15.       ds = new dataset()
  16.  
  17.       dr = ds.Tables(0).Rows(0)
  18.  
  19.       If NotPostBack Then
  20.  
  21.       tbPrice.Text = dr("Price")
  22.  
  23.       #etc...
  24.  
  25.       EndIf
  26.  
  27.       End Sub
  28.  
  29.       ##############
  30.  
  31.  
  32.       ##############
  33.  
  34.       Submit Button "Protected Sub "SubButton""
  35.  
  36.     dr.BeginEdit()
  37.  
  38.       dr("Price") = tbPrice.Text
  39.  
  40.       dr.EndEdit()
  41.  
  42.       Dim objCommandBuilder As New SqlCommandBuilder(da)
  43.  
  44.       da.Update(ds, 0)
  45.  
  46.       End of sub etc..
  47.       #############
  48.  


The code breaks at the line
"da.Update(ds, 0)", with the error -

invalidOperationException was unhandled by the user code
Dynamic SQL generation is not supported against multiple base tables.

This is because I'm doing a link between tables in my sql and the dataadapter is looking for a table to reference (well, i assume this is the problem),
however i've heard of different ways to remedy this e.g do a seperate dataadapter for updating or something.. but i really wouldnt know how to do this, so if someone could have a look at my code, and show me how i could go about this, or another way (being a newbie of .net i'm learning as i'm going along) i'd be really grateful!
Jan 15 '08 #1
1 3873
pureenhanoi
175 100+
Hi, I'm having a problem with my code,

I am doing the following - retrieving a field from a table, which is linked to another table, i'm only updating one of the fields in one of the two tables...


Expand|Select|Wrap|Line Numbers
  1.          ##############
  2.  
  3.       Page Load Sub
  4.  
  5.  
  6.       sqlselect = "Select ProductID,Name,Price from Products,Store Where Products.StoreID = Store.StoreID And StoreID = 7"
  7.  
  8.       connectionstring = dh.returnconnection # returns the connection string to the location of the database
  9.  
  10.  
  11.       sqlcon = new sqlconnection(connectionstring)
  12.  
  13.       da = new sqlDataAdapter(sqlselect,connectionstring)
  14.  
  15.       ds = new dataset()
  16.  
  17.       dr = ds.Tables(0).Rows(0)
  18.  
  19.       If NotPostBack Then
  20.  
  21.       tbPrice.Text = dr("Price")
  22.  
  23.       #etc...
  24.  
  25.       EndIf
  26.  
  27.       End Sub
  28.  
  29.       ##############
  30.  
  31.  
  32.       ##############
  33.  
  34.       Submit Button "Protected Sub "SubButton""
  35.  
  36.     dr.BeginEdit()
  37.  
  38.       dr("Price") = tbPrice.Text
  39.  
  40.       dr.EndEdit()
  41.  
  42.       Dim objCommandBuilder As New SqlCommandBuilder(da)
  43.  
  44.       da.Update(ds, 0)
  45.  
  46.       End of sub etc..
  47.       #############
  48.  


The code breaks at the line
"da.Update(ds, 0)", with the error -

invalidOperationException was unhandled by the user code
Dynamic SQL generation is not supported against multiple base tables.

This is because I'm doing a link between tables in my sql and the dataadapter is looking for a table to reference (well, i assume this is the problem),
however i've heard of different ways to remedy this e.g do a seperate dataadapter for updating or something.. but i really wouldnt know how to do this, so if someone could have a look at my code, and show me how i could go about this, or another way (being a newbie of .net i'm learning as i'm going along) i'd be really grateful!
I think the way of keeping a DataSet in memory and update it each time you need is worst way. The DataSet (as i think, it like RecordSet in VB6) just used to store data in a short periods of time, and it should be release as soon as possible.
I've never use Update to Recordset (or DataSet like you), so i never get problem with linked table.
Just store data of each table on seperate varriables, and update it in seperate statement
Jan 15 '08 #2

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

Similar topics

1
by: Wing | last post by:
Hi all, I have created 2 tables in sql database and join these 2 tables before assign the result to the dataset, and display the result in datagrid. Everything is fine up to this point. The...
2
by: Zuy Tran | last post by:
I'm trying to update my data source using the Update method in OleDbDataAdapter with automatic command generation and I got error "Dynamic SQL generation for the UpdateCommand is not supported...
1
by: Foef | last post by:
When I have a stored procedure, with multiple tables in MS Access, in a dataset and I change it in my DataGrid, I get the next message when I want to update my DataSet: ...
1
by: John | last post by:
I'm tring to update my Table which haven't a primary key from a DataGrid but I'm having the following error"Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand...
6
by: shil | last post by:
Hi, I am writing a windows app in .net 2003. I have a datagrid which gets data from a storedprocedure. My question is how can I update the data in the datagrid? I want to call another...
1
by: andrewcw | last post by:
I have just 1 table that I am updating, the SQL I use to generate the DataTable is complex using multiple tables, however when I view the fieldnames of the DataTable from the DataSet - everything...
2
by: nannu | last post by:
m using this code :........................... ======================================================================= OleDbConnection con =new OleDbConnection...
0
by: pieandpeas | last post by:
Hi, I'm having a problem with my code, I am doing the following - retrieving a field from a table, which is linked to another table, i'm only updating one of the fields in one of the two tables......
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.