Results 1 to 28 of 28

Thread: Ado.net ...

  1. #1

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437

    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 ...

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  3. #3

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ???

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by spoiledkid
    How about batch update ???
    AFAIK, it's only possible using the DataAdapter.

  6. #6

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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.

  7. #7
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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?

  8. #8

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ..

  9. #9
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  10. #10

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ???

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You can still use classic ADO in VB.NET. It has the BatchUpdate method, if that helps.

  12. #12
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    do you have an IM account?

  13. #13

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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.

  14. #14

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by CyberHawke
    do you have an IM account?
    whats an IM account ? no I do not have it.

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by spoiledkid
    whats an IM account ? no I do not have it.
    Ahem.

    MSN MEssenger.
    Yahoo
    ICQ
    AIM

  16. #16

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by mendhak
    Ahem.

    MSN MEssenger.
    Yahoo
    ICQ
    AIM
    I have MSN and Yahoo account ...

  17. #17
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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?

  18. #18
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    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

  19. #19
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    Ok, in your server component, create a method called:
    VB Code:
    1. Public Sub UpdateServer(ByVal ds As DataSet)
    2.     Dim cn As New SqlConnection("connectionstring")
    3.     Dim da As New SqlDataAdapter
    4.     Dim cmdSelect As New SqlCommand("SELECT FROM ...")
    5.     Dim cmdInsert As New SqlCommand("INSERT INTO ...")
    6.     Dim cmdUpdate As New SqlCommand("UPDATE TABLE ...")
    7.     Dim cmdDelete As New SqlCommand("DELETE FROM ...")
    8.  
    9.     da.SelectCommand = cmdSelect
    10.     da.InsertCommand = cmdInsert
    11.     da.UpdateCommand = cmdUpdate
    12.     da.DeleteCommand = cmdDelete
    13.  
    14.     da.Update(ds)
    15. 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.

  20. #20

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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.

  21. #21
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  22. #22

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ?

  23. #23
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  24. #24
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  25. #25

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ???

  26. #26
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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.

  27. #27

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    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 ?

  28. #28
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    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
  •  



Click Here to Expand Forum to Full Width