|
-
Jun 29th, 2004, 06:59 AM
#1
Thread Starter
Hyperactive Member
Ado.net ...
ADO.NET is not very flexible, is it ? I mean to update a datatable or dataset, I always need to keep its dataAdapter somewhere in the memory. There is no other way to directly update these objects in the DB, is there ?
I wrote a standard DLL with some functions. These functions will get you the data from DB in whichever form with any no. of parameters. They return dataTable or dataSet. They just temporarily open a dataAdapter to fill the datatable or dataset and then destroy the dataAdapter.
Now if user makes some changes to dataTable and sends it back to update, how do i update it ? I have already destroyed the dataAdapter .... ?? Is there any way or am I not understanding it very well ...
-
Jun 29th, 2004, 07:03 AM
#2
You can run a direct query on the database (UPDATE in your case).
Dim cmdUpdate As New System.Data.SqlClient.SqlCommand("UPDATE BLAH BLAH")
cmdUpdate.ExecuteNonQuery()
Is this what you are looking for?
-
Jun 29th, 2004, 07:06 AM
#3
Thread Starter
Hyperactive Member
Originally posted by mendhak
You can run a direct query on the database (UPDATE in your case).
Is this what you are looking for?
Yeah, thats good for single queries. How about batch update ???
-
Jun 29th, 2004, 07:15 AM
#4
Hyperactive Member
For batch updates you will need several objects.
A dataadapter, a dataset, 4 command objects and a connection object.
The four command objects will be coded for your SELECT INSERT UPDATE and DELETE statements, then associate them with your dataadapter.
After you have finished modifying your data, call the update method of the dataadapter.
-
Jun 29th, 2004, 07:16 AM
#5
Originally posted by spoiledkid
How about batch update ???
AFAIK, it's only possible using the DataAdapter.
-
Jun 29th, 2004, 07:17 AM
#6
Thread Starter
Hyperactive Member
Originally posted by mendhak
AFAIK, it's only possible using the DataAdapter.
Thats why I thought that ADO.NET is not as flexible as MS is bragging about it ... Now what do I do .. Is there a way to build that dataAdapter object while updating... my DA is gone once the DLL call is finished.
-
Jun 29th, 2004, 07:23 AM
#7
Hyperactive Member
Well actually, it's very flexible, but as with any object, in order to use it you need to maintain an in-memory reference to that object, this is true of any programming language.
Now I have a question, if your data adapter is gone from memory, where is your data that your users still have access to it?
-
Jun 29th, 2004, 07:25 AM
#8
Thread Starter
Hyperactive Member
Originally posted by CyberHawke
Well actually, it's very flexible, but as with any object, in order to use it you need to maintain an in-memory reference to that object, this is true of any programming language.
Now I have a question, if your data adapter is gone from memory, where is your data that your users still have access to it?
Data is in DataSet or DataTable which has been returned to UI layer .. dataAdapter is disposed once the data has been returned. I do not see it very flexible this way ... why do I have to maintain a freakin dataAdapter ??? My dataset or dataTable should be intelligent enough to do updates on there own ... just like VB6 recordSets ..
-
Jun 29th, 2004, 07:28 AM
#9
Hyperactive Member
ok, I agree that the need for the DataAdapter may not be as flexible as one might like, but there is a solution to your problem.
In your server component, try creating an update method that accepts your DataSet/DataTable object and then builds the adapter on the fly when the method is called. Not as simple as calling an update method on a DataSet, but should work nicely.
-
Jun 29th, 2004, 07:29 AM
#10
Thread Starter
Hyperactive Member
Originally posted by CyberHawke
ok, I agree that the need for the DataAdapter may not be as flexible as one might like, but there is a solution to your problem.
In your server component, try creating an update method that accepts your DataSet/DataTable object and then builds the adapter on the fly when the method is called. Not as simple as calling an update method on a DataSet, but should work nicely.
exactly, thats what I want .. but how ???
-
Jun 29th, 2004, 07:30 AM
#11
You can still use classic ADO in VB.NET. It has the BatchUpdate method, if that helps.
-
Jun 29th, 2004, 07:31 AM
#12
Hyperactive Member
do you have an IM account?
-
Jun 29th, 2004, 07:31 AM
#13
Thread Starter
Hyperactive Member
Originally posted by mendhak
You can still use classic ADO in VB.NET. It has the BatchUpdate method, if that helps.
My PM will kill me for this, we are trying to go to .NET, nobody wants to keep maintaining the backward compatibility non-sense which will eventually be removed completely.
-
Jun 29th, 2004, 07:32 AM
#14
Thread Starter
Hyperactive Member
Originally posted by CyberHawke
do you have an IM account?
whats an IM account ? no I do not have it.
-
Jun 29th, 2004, 07:33 AM
#15
Originally posted by spoiledkid
whats an IM account ? no I do not have it.
Ahem.
MSN MEssenger.
Yahoo
ICQ
AIM
-
Jun 29th, 2004, 07:35 AM
#16
Thread Starter
Hyperactive Member
Originally posted by mendhak
Ahem.
MSN MEssenger.
Yahoo
ICQ
AIM
I have MSN and Yahoo account ...
-
Jun 29th, 2004, 07:38 AM
#17
Originally posted by spoiledkid
I have MSN and Yahoo account ...
Now if only you were really Cameron Diaz... 
Oh, backtracking to your first post, is there a reason you're destroying the DataAdapter? Why not keep it alive'n'kickin for this eventual Batch Update?
-
Jun 29th, 2004, 07:38 AM
#18
This will be relevant to you at a later point in time, at which point you will thank me profusely:
http://msdn.microsoft.com/library/de...ta11082001.asp
-
Jun 29th, 2004, 07:43 AM
#19
Hyperactive Member
Ok, in your server component, create a method called:
VB Code:
Public Sub UpdateServer(ByVal ds As DataSet)
Dim cn As New SqlConnection("connectionstring")
Dim da As New SqlDataAdapter
Dim cmdSelect As New SqlCommand("SELECT FROM ...")
Dim cmdInsert As New SqlCommand("INSERT INTO ...")
Dim cmdUpdate As New SqlCommand("UPDATE TABLE ...")
Dim cmdDelete As New SqlCommand("DELETE FROM ...")
da.SelectCommand = cmdSelect
da.InsertCommand = cmdInsert
da.UpdateCommand = cmdUpdate
da.DeleteCommand = cmdDelete
da.Update(ds)
End Sub
I just remembered that there is a lot more code that has to go with this. While I do not recommend that you use the code that gets generated by the wizard in your project, you can create a data connection to the server by dragging a table from the Server Explorer tab in the .NET IDE and then use that code as a template for coding your method in your component.
-
Jun 29th, 2004, 07:47 AM
#20
Thread Starter
Hyperactive Member
Tx guys, but for some reason I am not convinced with this. Anyway, may be I have to keep the DA alive at all times. Tx again.
-
Jun 29th, 2004, 07:56 AM
#21
Hyperactive Member
Actually, this does work and quite nicely, I have a project where I have a server component that retrives my data from the server and returns it to the client. Then the client returns the dataset back to the server and calls a data adapter update method. The only problem is, it's written in C# and not appropriate for this forum.
-
Jun 29th, 2004, 08:54 AM
#22
Thread Starter
Hyperactive Member
how does your method works if dataset has more than one table in it ? it will always be generating commans for the first table ... wouldn'it ?
-
Jun 29th, 2004, 09:00 AM
#23
Hyperactive Member
Ahh.. There's the catch. I never could get this methodology to work with more than one table at a time. The best that I could do is have multiple sets of command objects and associate the ones that I needed for for updating the needed table. Again, not very flexible for what you need, but it does work.
-
Jun 29th, 2004, 09:11 AM
#24
PowerPoster
Hi,
I've never seen so many prompt responses!! Must be something to do with the icon
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 29th, 2004, 09:25 AM
#25
Thread Starter
Hyperactive Member
Originally posted by CyberHawke
Ahh.. There's the catch. I never could get this methodology to work with more than one table at a time. The best that I could do is have multiple sets of command objects and associate the ones that I needed for for updating the needed table. Again, not very flexible for what you need, but it does work.
Jesus christ, I hope what you are saying is wrong .. You cannot update multiple tables at once, then what the heck MS is braging about ???
-
Jun 29th, 2004, 09:43 AM
#26
Hyperactive Member
In reading the article that mendhak provided the link to (thanks dude) I would have to believe that my approach is the correct one. You cannot update multiple tables with a single update statement therefore it makes sense that you wouldn't be able to do that with this methodology either.
-
Jun 29th, 2004, 10:59 AM
#27
Thread Starter
Hyperactive Member
so in other words, rule of thumb would be ..
You would only be updating dataTables...
For each dataTable you will need separate DataAdapter...
Are these two statements correct ?
-
Jun 29th, 2004, 11:03 AM
#28
Hyperactive Member
Yes, I would consider them correct.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|