473,747 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting pointer to proper dataAdapter from dataset or dataTable


I would like to build some generic code that is able to figure out the
correct dataAdapter to apply changes to given a form with several
dataAdapters.

Any suggestions on the following?

Thank you.

=============== =============== ========
Private Sub SaveChanges(ByV al aContainer As Object)
Dim dt As DataTable
Dim ds As New DataSet
Dim bSaveMe As Boolean
Dim myDA As System.Data.Sql Client.SqlDataA dapter

For Each dt In Me.DS1.Tables
If Not dt.GetChanges(D ataRowState.Mod ified) Is Nothing Then
bSaveMe = True
End If

If bSaveMe Then
ds.Merge(dt.Sel ect("", "",
DataViewRowStat e.ModifiedCurre nt))
myDA = <<<<< figure out correct dataAdapter
here>>>>>> <<<=====NEED SUGGESTION HERE
myDA.Update(ds)
End If

bSaveMe = False

Next
Exit Sub
End Sub
=============== =============== ========
Nov 21 '05 #1
4 1786
Astro,

Probably you want to use the dataadapter created using the designer in your
generic code.

It is an easier approach to create the dataadapter than completly by code.

However before I write to much maybe can you tell if my expectation is
right?

Cor
Nov 21 '05 #2
Thanks Cor - I end up reading your posts a lot and have found them helpful

I want to have a 'system' where I do not have to write a line of code for
each dataAdapter on a form. On the form I currently am working on I have 7
SQLDataAdaptors --

The following allows me to catch changes on any datagrid on a form without
'hardCoding' the names of each table/datagrid....
=============== =======
For Each dt In Me.DS1.Tables
If Not dt.GetChanges(D ataRowState.Mod ified) Is Nothing
etc.....
=============== =======

If the .NET object library allows me to find each table's DataAdapter (in my
Dataset) I can write a loop that walks through every table and apply changes
back to the database....aga in without hardcoding the names of each
dataAdapter.... .

Is this clear?

If I must I can use the table name from the Dataset to loop through all the
dataAdapters on my form till I get a string match......but I wonder if this
information is not stored in the DataSet itself......
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP14.phx.gbl. ..
Astro,

Probably you want to use the dataadapter created using the designer in
your generic code.

It is an easier approach to create the dataadapter than completly by code.

However before I write to much maybe can you tell if my expectation is
right?

Cor

Nov 21 '05 #3
Astro,

.....but I wonder if this information is not stored in the DataSet
itself......

It will be in the next version of VBNet.

However see by instance this sample how to make your dataadapter by code,
than you don't have it on your screen.

However you need the updatecommand, insertcommand, deletecommand properties
from the dataadapter. For that are two approaches, you use first the
designer and copies them from the designer part, or you use the
commandbuilder (which goes fine by simple selects).

See some threads I wrote about above.
http://www.windowsformsdatagridhelp....7-5595f8147624
http://msdn.microsoft.com/library/de...mberstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
It has not really much sense if you use one dataadapter.

I don't like all those dataadapters in my form as well. I find it too a nice
approach to create a component (selecting an item component) and use that to
make a databaseclass (databaselayer) .

I hope this helps,

Cor
Cor
Nov 21 '05 #4
Thanks Cor ))

this is what i ended up doing (with some code snippets lifted from

5. enders Oct 11 2002, 9:30 am post on this newsgroup:
=============== =============== =======
Private Sub SaveChanges_DA( ByVal ads As DataSet)
'saves are at table-level scope
'need to find correct dataAdapter for passed dataset
'this info is not available in this version of vb.net dataset object
'assumptions: 1) ds has one table and da has one table

Dim propInfos() As System.Reflecti on.PropertyInfo
Dim propInfo As System.Reflecti on.PropertyInfo

propInfos = Me.GetType.GetP roperties()

For Each propInfo In propInfos
If propInfo.Proper tyType.FullName =
"System.Data.Sq lClient.SqlData Adapter" Then
Dim da As System.Data.Sql Client.SqlDataA dapter
da = CType(propInfo. GetValue(Me, Nothing),
System.Data.Sql Client.SqlDataA dapter)
If da.TableMapping s(0).DataSetTab le.ToString.ToL ower =
ads.Tables(0).T ableName.ToStri ng.ToLower Then
'have match - this da is the source for the passed
dataset
Try
da.Update(ads)
Me.DS1.AcceptCh anges()
Catch exc As Exception
MsgBox(exc.Mess age)
End Try
End If

End If
Next
=============== =============== =======

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:Ot******** ********@TK2MSF TNGP12.phx.gbl. ..
Astro,

.....but I wonder if this information is not stored in the DataSet
itself..... .

It will be in the next version of VBNet.

However see by instance this sample how to make your dataadapter by code,
than you don't have it on your screen.

However you need the updatecommand, insertcommand, deletecommand
properties from the dataadapter. For that are two approaches, you use
first the designer and copies them from the designer part, or you use the
commandbuilder (which goes fine by simple selects).

See some threads I wrote about above.
http://www.windowsformsdatagridhelp....7-5595f8147624
http://msdn.microsoft.com/library/de...mberstopic.asp
http://msdn.microsoft.com/library/de...classtopic.asp
It has not really much sense if you use one dataadapter.

I don't like all those dataadapters in my form as well. I find it too a
nice approach to create a component (selecting an item component) and use
that to make a databaseclass (databaselayer) .

I hope this helps,

Cor
Cor

Nov 21 '05 #5

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

Similar topics

5
2253
by: randy | last post by:
Hello all, I have a DataTable which I am building column by column and adding rows after each new column. The DataTable columns match the columns in my database table. I'm building the DataTable first and I then want to roll through the DataTable while in memory checking for errors and then commit the rows to my database table (btw this is in ASP.NET). Is it possible to have data in a datable before attaching at DataAdapter? I'm a...
4
2624
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes, then written to the database... or at least that's what's supposed to be happening. Unfortunately, I've discovered that while it appears that when I create a new record/row I'm successfully updating the Access database, once the Update is...
3
5296
by: Saso Zagoranski | last post by:
Hi! A question about database tables... I have a SELECT statement: SELECT something FROM someTable WHERE code = @code The parameter code starts with 1 and is autoincremented... Now I want to add a row to the database and I do it like this: DataSet dataSet = new DataSet();
13
2089
by: Doug Bell | last post by:
Hi, I thought I had this sorted this morning but it is still a problem. My application has a DataAccess Class. When it starts, it: Connects to a DB (OLE DB) If it connects it uses an OleDbCommand with an SQL String and the connection it has a DataAdapter with the command then it fills the DataSet's DataTable with the streamed data.
2
13969
by: susan.f.barrett | last post by:
Hi, Despite me being able to type the following in to SQL Server and it updating 1 row: > updatestockcategory 1093, 839 In my code, it is not updating any rows. dataSet = new DataSet();
2
5224
by: MDB | last post by:
Hello All, I have a data grid that I fill using a dataset. The results of the query has around 15 columns and 500 rows (and growing). The reason I am using the datagrid is so the end users can auto sort and page so I would like to keep using the datagrid. My problem is that when I call DataAdapter.Fill, it takes a very long time and is even causing the web page to time out. Does anyone know why the fill is taking so long (15-20 sec)...
0
4556
by: mike1402 | last post by:
Hi ! I get the error below sometimes when retrieving a big amount of data using Datadapter.Fill(dataset,"table"). But when I send the command Fill again, there is no error. Is it a fault of IBM.Data.DB2.iSeries; Version: v1.0.3705 (is there an newer one for OS/400 Version ist V5R3 ?) or is it a hardware faoult (memory of as400 or pc) ? br mike Es wurde versucht, im geschützten Speicher zu lesen oder zu schreiben. Dies ist häufig ein...
3
2351
by: Fred Chateau | last post by:
Any obvious reason here why data is not being loaded into the database? SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); dataAdapter.Fill(dataSet, "POI_Entity"); DataRow dataRow = dataSet.Tables.NewRow(); dataRow = 1; dataRow = dataSet.Identity.POI_Entity_ID; dataRow = dataSet.Identity.Chain_ID;
2
3879
by: BobLewiston | last post by:
Some of you may have seen my earlier thread “PasswordHash NULL problem”. I’ve started a new thread because investigation has shown that the problem is actually quite different than I previously stated. Also please note that this is unrelated to another of my previous threads, “dataAdapter.Update problem”, which incidentally has been resolved. I’m learning SQL. I’m accessing database SQL2008 AdventureWorks, table Person.Contact, which has a...
0
8818
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
9522
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
9354
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...
1
9307
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9223
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
6790
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
6067
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
4588
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
4860
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.