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

implement a Join between 2 DataTables (Dynamic SQL generation is not supported against multiple base tables)

Hi,

For my VB.NET application I have the following situation:
2 tables on my SQL Server: tblAccounts and tblRules. For each Account there
are many Rules (so tblRules is linked to my tblAccounts by the Account). In
the tblAccounts thee is a field Company which occurs many times (there is
more than one Account for each Company:).

Whet I want to do on my Fom is this: I have a combobox with all my company's
in it. When I choce a Company in it, I want it to give me all the Rules for
all the Accounts that this Company has.

I tried it like this:
'TblRULES
strSql = "SELECT * FROM tblRules INNER JOIN tblAccounts ON
tblRules.Account = tblAccounts.Account"

Dim cmdSql As New SqlCommand(strSql, conSql)
dadRules = New SqlDataAdapter(cmdSql)

Dim cbSql As New SqlCommandBuilder(dadRules)
cbSql.GetUpdateCommand()

dtsRules = New DataSet
dadRules.Fill(dtsRules, "tblRules")

Unfortunately this gives me this error:
Dynamic SQL generation is not supported against multiple base tables. at
System.Data.Common.CommandBuilder.BuildInformation (DataTable schemaTable)

So I guess it's not good to put a join in a SqlCommand and try to do an
Update afterwards on it. The 'good' way should be to somewhere be able to
put tblRules and tblAccounts as two different tables in my DataSet, and
perform the Join n the DataSet or something like that when I need to do a
search on the Company.

does anybody knows how to do this? Or to get rid of that error? I just need
the best way to get this working!

Thanks a lot in advance! Any help will be really appreciated!

Pieter


Nov 21 '05 #1
4 23280
The problem is with the CommandBuilder object. It works only for simplest of
the select commands. Also it requires to execute the select command to
generate the metadata required for generating update, insert and delete
commands.
So instead of using the CommandBuilder to generate Update command, write the
update command directly as follows:
dadRules.UpdateCommand.CommandText = "update command text"

Hope this helps.
Sameeksha

"DraguVaso" wrote:
Hi,

For my VB.NET application I have the following situation:
2 tables on my SQL Server: tblAccounts and tblRules. For each Account there
are many Rules (so tblRules is linked to my tblAccounts by the Account). In
the tblAccounts thee is a field Company which occurs many times (there is
more than one Account for each Company:).

Whet I want to do on my Fom is this: I have a combobox with all my company's
in it. When I choce a Company in it, I want it to give me all the Rules for
all the Accounts that this Company has.

I tried it like this:
'TblRULES
strSql = "SELECT * FROM tblRules INNER JOIN tblAccounts ON
tblRules.Account = tblAccounts.Account"

Dim cmdSql As New SqlCommand(strSql, conSql)
dadRules = New SqlDataAdapter(cmdSql)

Dim cbSql As New SqlCommandBuilder(dadRules)
cbSql.GetUpdateCommand()

dtsRules = New DataSet
dadRules.Fill(dtsRules, "tblRules")

Unfortunately this gives me this error:
Dynamic SQL generation is not supported against multiple base tables. at
System.Data.Common.CommandBuilder.BuildInformation (DataTable schemaTable)

So I guess it's not good to put a join in a SqlCommand and try to do an
Update afterwards on it. The 'good' way should be to somewhere be able to
put tblRules and tblAccounts as two different tables in my DataSet, and
perform the Join n the DataSet or something like that when I need to do a
search on the Company.

does anybody knows how to do this? Or to get rid of that error? I just need
the best way to get this working!

Thanks a lot in advance! Any help will be really appreciated!

Pieter


Nov 21 '05 #2
Use the Design View for any complicated queries and use the Database Diagram
for relationships between tables of a database. You can explore through
these features using the Server Explorer in Visual Studio (View->Server
Explorer or, easier, CTRL + ALT + S).
Good luck,

Bram.
su*****@geticasoftware.ro

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:eJ****************@TK2MSFTNGP09.phx.gbl...
Hi,

For my VB.NET application I have the following situation:
2 tables on my SQL Server: tblAccounts and tblRules. For each Account there are many Rules (so tblRules is linked to my tblAccounts by the Account). In the tblAccounts thee is a field Company which occurs many times (there is
more than one Account for each Company:).

Whet I want to do on my Fom is this: I have a combobox with all my company's in it. When I choce a Company in it, I want it to give me all the Rules for all the Accounts that this Company has.

I tried it like this:
'TblRULES
strSql = "SELECT * FROM tblRules INNER JOIN tblAccounts ON
tblRules.Account = tblAccounts.Account"

Dim cmdSql As New SqlCommand(strSql, conSql)
dadRules = New SqlDataAdapter(cmdSql)

Dim cbSql As New SqlCommandBuilder(dadRules)
cbSql.GetUpdateCommand()

dtsRules = New DataSet
dadRules.Fill(dtsRules, "tblRules")

Unfortunately this gives me this error:
Dynamic SQL generation is not supported against multiple base tables. at
System.Data.Common.CommandBuilder.BuildInformation (DataTable schemaTable)

So I guess it's not good to put a join in a SqlCommand and try to do an
Update afterwards on it. The 'good' way should be to somewhere be able to
put tblRules and tblAccounts as two different tables in my DataSet, and
perform the Join n the DataSet or something like that when I need to do a
search on the Company.

does anybody knows how to do this? Or to get rid of that error? I just need the best way to get this working!

Thanks a lot in advance! Any help will be really appreciated!

Pieter

Nov 21 '05 #3
You can only update 1 of the tables in the join. So pick one, change the SQL
query for the adapter to be a SELECT just from that table of the appropriate
columns, and then create the command builder. That way the command builder
will ignore any other columns, and the update will be able to update that
one table.

"DraguVaso" <pi**********@hotmail.com> wrote in message
news:eJ****************@TK2MSFTNGP09.phx.gbl...
Hi,

For my VB.NET application I have the following situation:
2 tables on my SQL Server: tblAccounts and tblRules. For each Account there are many Rules (so tblRules is linked to my tblAccounts by the Account). In the tblAccounts thee is a field Company which occurs many times (there is
more than one Account for each Company:).

Whet I want to do on my Fom is this: I have a combobox with all my company's in it. When I choce a Company in it, I want it to give me all the Rules for all the Accounts that this Company has.

I tried it like this:
'TblRULES
strSql = "SELECT * FROM tblRules INNER JOIN tblAccounts ON
tblRules.Account = tblAccounts.Account"

Dim cmdSql As New SqlCommand(strSql, conSql)
dadRules = New SqlDataAdapter(cmdSql)

Dim cbSql As New SqlCommandBuilder(dadRules)
cbSql.GetUpdateCommand()

dtsRules = New DataSet
dadRules.Fill(dtsRules, "tblRules")

Unfortunately this gives me this error:
Dynamic SQL generation is not supported against multiple base tables. at
System.Data.Common.CommandBuilder.BuildInformation (DataTable schemaTable)

So I guess it's not good to put a join in a SqlCommand and try to do an
Update afterwards on it. The 'good' way should be to somewhere be able to
put tblRules and tblAccounts as two different tables in my DataSet, and
perform the Join n the DataSet or something like that when I need to do a
search on the Company.

does anybody knows how to do this? Or to get rid of that error? I just need the best way to get this working!

Thanks a lot in advance! Any help will be really appreciated!

Pieter

Nov 21 '05 #4
I had a similar problem, which I solved by using 2 dataadapters: one
which SELECTs without a JOIN and is used for UPDATEing, and another with
the JOIN. They both work with the same dataset - one reads, the other writes
DraguVaso wrote:
Hi,

For my VB.NET application I have the following situation:
2 tables on my SQL Server: tblAccounts and tblRules. For each Account there
are many Rules (so tblRules is linked to my tblAccounts by the Account). In
the tblAccounts thee is a field Company which occurs many times (there is
more than one Account for each Company:).

Whet I want to do on my Fom is this: I have a combobox with all my company's
in it. When I choce a Company in it, I want it to give me all the Rules for
all the Accounts that this Company has.

I tried it like this:
'TblRULES
strSql = "SELECT * FROM tblRules INNER JOIN tblAccounts ON
tblRules.Account = tblAccounts.Account"

Dim cmdSql As New SqlCommand(strSql, conSql)
dadRules = New SqlDataAdapter(cmdSql)

Dim cbSql As New SqlCommandBuilder(dadRules)
cbSql.GetUpdateCommand()

dtsRules = New DataSet
dadRules.Fill(dtsRules, "tblRules")

Unfortunately this gives me this error:
Dynamic SQL generation is not supported against multiple base tables. at
System.Data.Common.CommandBuilder.BuildInformation (DataTable schemaTable)

So I guess it's not good to put a join in a SqlCommand and try to do an
Update afterwards on it. The 'good' way should be to somewhere be able to
put tblRules and tblAccounts as two different tables in my DataSet, and
perform the Join n the DataSet or something like that when I need to do a
search on the Company.

does anybody knows how to do this? Or to get rid of that error? I just need
the best way to get this working!

Thanks a lot in advance! Any help will be really appreciated!

Pieter

Nov 21 '05 #5

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

Similar topics

6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
0
by: RJN | last post by:
Hi My web service receives an object of type say MyObject. I want to serialize this object,and then validate the xml against the main xsd. When validation happens, it should also validate...
0
by: RJN | last post by:
hi My web service receives an object of type say MyObject. I want to serialize this object,and then validate the xml against the main xsd. When validation happens, it should also validate...
2
by: Irfan | last post by:
hi, I am getting the following error. Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information when i try to use da.update I squeezed...
1
by: Felix_WafyTech | last post by:
Hi, I'm working with the ObjectDatasource and the application is getting more and more chatty. Is there a way I could make the ObjectDatasource support multiple DataTables that could be...
0
by: Gancy | last post by:
Hi, I have data access tier designed in such a way, just by changnging application settings, same lines of code is made to work with both MS SQL Server or MS Access. Code works fine with MS SQL...
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
4
by: HLCruz via AccessMonster.com | last post by:
I am working with a database that has client information separated in to 4 related tables - tFolder, tAddress, tEmail, tPhone number. In addition there are related tables tGifts and tCalls. The...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
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: 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...
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
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,...
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.