473,732 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO.NET Update two tables using one SQLCommandBuild er

Can I use one Data Adapter and one Command Builder to update amny tables?
Currently in my data adapter I query two tables and fill them into two tables
in a data set. When I make a change to a record in the second table and call
the update method of the data adapter the command builders update command
text is for the first table. Can the command builder handle two tables?

Code example:

Dim oCOnn As New SqlConnection(" Data Source=.;" & _
"Initial
Catalog=Databas ename;" & _
"Integrated Security=SSPI")
Dim oAdt As New SqlDataAdapter( "Select * from location; select *
from vendor", oCOnn)
Dim oSet As New DataSet
Dim ocommbuild As New SqlCommandBuild er(oAdt)

oAdt.Fill(oSet)
oSet.Tables(1). Rows(1).Item("N otes") = "Hello"
Debug.WriteLine (ocommbuild.Get UpdateCommand.C ommandText)

oAdt.Update(oSe t.Tables(1))
Jul 26 '05 #1
10 9380
Just use two separate commandbuilders , one for each query. Or, you can
specify a different select query for it and then call update- but it's
easier to just use two of them. Also, you probably want to use a
DataRelation on those tables if they are related in any form, just to ensure
that nothing happens client side that won't fly when it gets back to the
server.

All in all though - I'm not a big fan of CommandBuilders - at least not in
this version of the framework - Bill Vaughn has a great article on why at
www.betav.com ->Articles -> MSDN - Weaning Developers from the
CommandBuilder.

As an aside... It's not a commonly known risk but believe it or not,
connection strings are susceptible to injection attacks as well and as it
stands, allowing user data to create the connection string could get you in
trouble potentially. As such, I'd be careful about that (ie don't do it
-) ). Store it in a config file or in isolated storage and ideally encrypt
it. Yes, you're using a trusted connection so that mitigates the risk of
having it stored in plain text - but it's a good practice and if you ever n
eed to change the authentication model, the code will be in place already.
Please note that in no way am I trying to lecture or anything - just figured
I'd mention it in case you were interested - when I learned about an
injection attack with a connectionstrin g- I was quite surprised b/c I didn't
realize such a thing was possible.

HTH,

Bill
"Hank1234" <Ha******@discu ssions.microsof t.com> wrote in message
news:45******** *************** ***********@mic rosoft.com...
Can I use one Data Adapter and one Command Builder to update amny tables?
Currently in my data adapter I query two tables and fill them into two
tables
in a data set. When I make a change to a record in the second table and
call
the update method of the data adapter the command builders update command
text is for the first table. Can the command builder handle two tables?

Code example:

Dim oCOnn As New SqlConnection(" Data Source=.;" & _
"Initial
Catalog=Databas ename;" & _
"Integrated Security=SSPI")
Dim oAdt As New SqlDataAdapter( "Select * from location; select *
from vendor", oCOnn)
Dim oSet As New DataSet
Dim ocommbuild As New SqlCommandBuild er(oAdt)

oAdt.Fill(oSet)
oSet.Tables(1). Rows(1).Item("N otes") = "Hello"
Debug.WriteLine (ocommbuild.Get UpdateCommand.C ommandText)

oAdt.Update(oSe t.Tables(1))

Jul 26 '05 #2
I don't understand how to use two different command builders when I have
selected from two different tables in the one data adapter. When I create a
command builder it only accepts the data adapter and since my data adapter
had two select statements in the command text how do I create a second
builder to use the second select statement. I hope this makes sense

"W.G. Ryan MVP" wrote:
Just use two separate commandbuilders , one for each query. Or, you can
specify a different select query for it and then call update- but it's
easier to just use two of them. Also, you probably want to use a
DataRelation on those tables if they are related in any form, just to ensure
that nothing happens client side that won't fly when it gets back to the
server.

All in all though - I'm not a big fan of CommandBuilders - at least not in
this version of the framework - Bill Vaughn has a great article on why at
www.betav.com ->Articles -> MSDN - Weaning Developers from the
CommandBuilder.

As an aside... It's not a commonly known risk but believe it or not,
connection strings are susceptible to injection attacks as well and as it
stands, allowing user data to create the connection string could get you in
trouble potentially. As such, I'd be careful about that (ie don't do it
-) ). Store it in a config file or in isolated storage and ideally encrypt
it. Yes, you're using a trusted connection so that mitigates the risk of
having it stored in plain text - but it's a good practice and if you ever n
eed to change the authentication model, the code will be in place already.
Please note that in no way am I trying to lecture or anything - just figured
I'd mention it in case you were interested - when I learned about an
injection attack with a connectionstrin g- I was quite surprised b/c I didn't
realize such a thing was possible.

HTH,

Bill
"Hank1234" <Ha******@discu ssions.microsof t.com> wrote in message
news:45******** *************** ***********@mic rosoft.com...
Can I use one Data Adapter and one Command Builder to update amny tables?
Currently in my data adapter I query two tables and fill them into two
tables
in a data set. When I make a change to a record in the second table and
call
the update method of the data adapter the command builders update command
text is for the first table. Can the command builder handle two tables?

Code example:

Dim oCOnn As New SqlConnection(" Data Source=.;" & _
"Initial
Catalog=Databas ename;" & _
"Integrated Security=SSPI")
Dim oAdt As New SqlDataAdapter( "Select * from location; select *
from vendor", oCOnn)
Dim oSet As New DataSet
Dim ocommbuild As New SqlCommandBuild er(oAdt)

oAdt.Fill(oSet)
oSet.Tables(1). Rows(1).Item("N otes") = "Hello"
Debug.WriteLine (ocommbuild.Get UpdateCommand.C ommandText)

oAdt.Update(oSe t.Tables(1))


Jul 26 '05 #3
Hank,

Bill wrote that in as in my opinion does not matter.
However when you want the result of the commandbuilder like this.
Dim mycmd as new SQLCommandBuild er(DA1)
mycmd = new SQLCommandBuild er(DA2)

Does give it give AFAIK not much advantages above this
Dim myCmd1 as new SQLCommandBuild er(DA1)
Dim myCmd2 as new SQLCommandBuild er(DA2)

I prefer the last.

Just my thought

Cor
Jul 26 '05 #4
Bill,

This one always triggers me.
Store it in a config file or in isolated storage and ideally encrypt it.


Do you want to tell that the security model from Windows is so rotten that
somebody who can reach that is not easily able to encrypt a string.

I am almost sure that that is not what you want to tell, not after that
bunch of patches we get forever

:-)

Cor
Jul 26 '05 #5
You can do both. In this case, what I recommended doing was using Windows
Authentication AND storing the connection string encrypted. You are storing
it somewhere and you are storing it either plaintext or not. So you can
store it in code for instance, as a constant or a regular string, or you can
store it elsewhere like a configuration file. Either way, you're storing it
somewhere. So all I'm recommending doing is storing it in a configuration
file or isolated storage, and storing it encrypted [you can use Windows
authentication or not - either way I'd recommend the same approach]. I see
0 value in storing a connectionstrin g in plaintext for any reason. If you
have it being used on an internal network that's 'secure', that mitigates
some of the risk, but why publicize the database name or server name? And
if you change your mind later and need to use Mixed mode authentication for
example, you'll already have the code in place
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:Oi******** ******@tk2msftn gp13.phx.gbl...
Bill,

This one always triggers me.
Store it in a config file or in isolated storage and ideally encrypt it.


Do you want to tell that the security model from Windows is so rotten that
somebody who can reach that is not easily able to encrypt a string.

I am almost sure that that is not what you want to tell, not after that
bunch of patches we get forever

:-)

Cor

Jul 27 '05 #6
It makes sense ;-)

LEt me begin first by saying again that I"m not a big fan of
commandbuilders . If you look the code they generate, you'll understand why.
Anyway, to answer your question, you'd need to create two commandbuilders
and to do so, you'd need two dataadapters (each one containing one of the
select statements) or one dataadapter and change the commandtext. Neither
of these are elegant but CommandBUilders are NOT flexible in this regard (or
in respect to concurrency handling). As such, you're hands are tied if you
want to use them.

In Bill V's article, he mentions rolling your own code and I definitely
prefer this approach 99.9999% of the time over the commandbuilder.

HTH,

Bill
"Hank1234" <Ha******@discu ssions.microsof t.com> wrote in message
news:89******** *************** ***********@mic rosoft.com...
I don't understand how to use two different command builders when I have
selected from two different tables in the one data adapter. When I create
a
command builder it only accepts the data adapter and since my data adapter
had two select statements in the command text how do I create a second
builder to use the second select statement. I hope this makes sense

"W.G. Ryan MVP" wrote:
Just use two separate commandbuilders , one for each query. Or, you can
specify a different select query for it and then call update- but it's
easier to just use two of them. Also, you probably want to use a
DataRelation on those tables if they are related in any form, just to
ensure
that nothing happens client side that won't fly when it gets back to the
server.

All in all though - I'm not a big fan of CommandBuilders - at least not
in
this version of the framework - Bill Vaughn has a great article on why
at
www.betav.com ->Articles -> MSDN - Weaning Developers from the
CommandBuilder.

As an aside... It's not a commonly known risk but believe it or not,
connection strings are susceptible to injection attacks as well and as it
stands, allowing user data to create the connection string could get you
in
trouble potentially. As such, I'd be careful about that (ie don't do it
-) ). Store it in a config file or in isolated storage and ideally
encrypt
it. Yes, you're using a trusted connection so that mitigates the risk of
having it stored in plain text - but it's a good practice and if you ever
n
eed to change the authentication model, the code will be in place
already.
Please note that in no way am I trying to lecture or anything - just
figured
I'd mention it in case you were interested - when I learned about an
injection attack with a connectionstrin g- I was quite surprised b/c I
didn't
realize such a thing was possible.

HTH,

Bill
"Hank1234" <Ha******@discu ssions.microsof t.com> wrote in message
news:45******** *************** ***********@mic rosoft.com...
> Can I use one Data Adapter and one Command Builder to update amny
> tables?
> Currently in my data adapter I query two tables and fill them into two
> tables
> in a data set. When I make a change to a record in the second table and
> call
> the update method of the data adapter the command builders update
> command
> text is for the first table. Can the command builder handle two tables?
>
> Code example:
>
> Dim oCOnn As New SqlConnection(" Data Source=.;" & _
> "Initial
> Catalog=Databas ename;" & _
> "Integrated
> Security=SSPI")
> Dim oAdt As New SqlDataAdapter( "Select * from location; select *
> from vendor", oCOnn)
> Dim oSet As New DataSet
> Dim ocommbuild As New SqlCommandBuild er(oAdt)
>
> oAdt.Fill(oSet)
> oSet.Tables(1). Rows(1).Item("N otes") = "Hello"
> Debug.WriteLine (ocommbuild.Get UpdateCommand.C ommandText)
>
> oAdt.Update(oSe t.Tables(1))
>
>


Jul 27 '05 #7
Bill,

Why encrypt something when it is unreachable, that was the sense of my
question.

It is in a metaphor something as hiring a safe in a quality bank for your
diamonds and put those than in your own small inferior safe inside that safe
with a code lock on that.

Cor
Jul 27 '05 #8
It's not unreachable. Many security breaches occur from inside the firewall
by employees that have access that outsiders don't. Sure, encrypting
information doesn't mean that a savvy adversary couldn't get it, but there
is virtually 0 cost assoicated with encrypting it so making it more
difficult to tamper with is practically free..

And more importantly, if you have to change the database or later move to
mixed mode authentication, you can avoid a recompile by moving it to a
configuration file. And if it's already encrypted, then you won't have to
change 1 line of code to accomodate this change. In addition, by obscuring
the name of the db, you could stop someone from easily changing it to an
additional or different server. I know personally of a major US bank where
an intern found a script of part of the db and loaded an Oracle database on
his machine. He went into a VB6 application and changed the settings to
point over to his machine's db and then ran the application like he normally
would - checking all the data that came back and forth. Since multiple
servers were used, he did this one at a time with a few different databases
and found out quite a bit information from this. Fortunately he was fired
after being discovered - but this is a prime example of something that
couldn't have happened (at least not as easliy) if the server info was
encrypted.


"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Bill,

Why encrypt something when it is unreachable, that was the sense of my
question.

It is in a metaphor something as hiring a safe in a quality bank for your
diamonds and put those than in your own small inferior safe inside that
safe with a code lock on that.

Cor

Jul 27 '05 #9
Bill,
I know personally of a major US bank where an intern found a script


He did, as you describe it, not found it in a *safe* unreachable place,
maybe he was by instance the one who wrote it. For that there is no
protection there will be always some persons who knows it.

For me this as you propose sounds the same as those persons who set in their
programs
integer a = 2;
if(a!=2) MessageBox.Show ("the value of a is wrong");

:-)

This does not mean that I am against encrypting of connectionstrin g. There
are situations that I agree with that advice completly. However if it is in
a securit unreachable place. Than it looks for me a little bit overdone.

However let stop the discussion, we don't agree in this, but that is
sometimes very well.

:-)

Cor
Jul 27 '05 #10

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

Similar topics

3
2267
by: LP | last post by:
Hello, In the past I used SqlCommandBuilder and SqlDataAdapter .Update method to apply changes in a DataTable back to its table source in SQL Server. It worked fine when DataSet had only 1 table, this time I have 2 tables in a dataset and I want to update them all at once. However it only updates the first one and fails when attempts to update 2nd table.. Has anyone done anything like that? It looks like SqlCommandBuilder generates...
1
2994
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 problem come up when I want to delete one of rows in datagrid and update the change to the corresponding table. The error msg show up "Dynamic SQL generation is not supported against multiple base tables."
4
3809
by: Oscar Thornell | last post by:
Hi, I have a relativley large/complex typed dataset that contains 7-8 tables and some supporting relational tables (lookups) for many-to-many relations. A good exampel would be a dataset that contained the whole Northwind database with all tables and relations. In my business logic I will retrive a populated instance of the dataset and perform some operations (adding/deleting/updating of rows in various tables...).
10
440
by: Hank1234 | last post by:
Can I use one Data Adapter and one Command Builder to update amny tables? Currently in my data adapter I query two tables and fill them into two tables in a data set. When I make a change to a record in the second table and call the update method of the data adapter the command builders update command text is for the first table. Can the command builder handle two tables? Code example: Dim oCOnn As New SqlConnection("Data Source=.;" &...
1
2089
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 matches: What dont I understand here: ( The error I get is : Dynamic SQL generation is not supported against multiple base tables ). But My DataSet is 1 Table, and my target is 1 table, Why the error ?? Thanks : try {
1
2130
by: Pietro Ova | last post by:
Hello, I wrote a little program to understand the ADO.NET's mechanism. It's a common program with a datagrid, textboxes and a toolstripbar with usually buttons. The problem is that meanwhile i add rows to dataset the save button works when i remove some of them the update method doesn't work. Please see the following code: public Popola() { InitializeComponent(); string connstring = "Data Source =...
0
909
by: k3nTm | last post by:
Good day!!! can you help me with my code on whats wrong with it. I want to update my MSSQLSERVER database from a DataSet. and there's nothing happen with my Database. Here is my code: string ConnString = "Data Source=localhost\\sqlexpress;Initial Catalog=dbSample;Integrated Security=SSPI"; string SelectData = "SELECT * FROM TblIndex"; int added = 0;
0
909
OuTCasT
by: OuTCasT | last post by:
can some please tell me how to update a table with data from a dataset what ive done is fill the dataset with the adapter and used a for Next loop to step into each row and display it into text boxes on the form. on the save button Dim sqlCon As SqlConnection = New SqlConnection("Server=(local);Data Source=.\SQLEXPRESS;Initial Catalog=Payday10;Integrated Security=True;Pooling=False") Dim daEmployee As New SqlDataAdapter("select *...
1
2770
by: sachinkale123 | last post by:
Hi I am working in a Windows C# application. I m using Dataset. But whenever I updated the dataset it gets updated. I can see the changes in dataset but using SQLAdapter.Update(Dataset) command It is not updating the table. See my Code: string connectionString = "server=ADJ-IND-01-0012\\SQLEXPRESS;database=Master;uid=sa;pwd=1234"; SqlConnection mySqlConnection = new SqlConnection(connectionString); ...
0
8946
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
8774
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
9307
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
9181
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...
1
6735
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
6031
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
4550
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...
1
3261
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
2
2721
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.