|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ADO Update Code Re usemy Datatables. So I just thought of something - shouldn't I just put all the update code in one place? I don't have access to VS2005 on this PC, but I was thinking of something along these lines '*************************************************************** Function FillTable(stSQL as string) as Datatable ' Open Connection ' Create data adapter ' Fill Datatable ' Close connection End Function Function UpdateTable(stCommandText as string, Params as Parameters, dtUpdate as Datatable) as long 'Open Connection 'Create data adapter 'Create Updatecommand with stCommandText and the parameters collection 'Have the adapter run the command ' Close connection 'Return number of rows updated End Function To use these functions, have something like Dim stSelect as string = "Select CustomerID, CustomerName, CustomerSales FROM Customer" Dim dtCustomer as new Datatable = Filltable(stSelect) ' Do processing ' Create parameters Dim stUpdateText as string = "UPDATE Customers SET CustomerSales = ? WHERE CustomerID = ?" Dim lRows as Long = Updatetable(stUpdateText, paramsCustomer,dtCustomer) '*************************************************************** Hope that made sense! Could also have Add and Delete functions. Are any of you already doing something similiar? Let me know if you think of anything I may be missing. Thanks Vayse How about taking this one step further and making those functions part of a
stand-alone class and violla! You now have your own custom data class. Show quote "Vayse" <nospam@microsoft.com> wrote in message news:OW3Uvv5TGHA.5332@tk2msftngp13.phx.gbl... >I don't know about you, but I'm use similiar code again and again to update >my Datatables. So I just thought of something - shouldn't I just put all >the update code in one place? > I don't have access to VS2005 on this PC, but I was thinking of something > along these lines > > '*************************************************************** > Function FillTable(stSQL as string) as Datatable > ' Open Connection > ' Create data adapter > ' Fill Datatable > ' Close connection > End Function > > Function UpdateTable(stCommandText as string, Params as Parameters, > dtUpdate as Datatable) as long > 'Open Connection > 'Create data adapter > 'Create Updatecommand with stCommandText and the parameters collection > 'Have the adapter run the command > ' Close connection > 'Return number of rows updated > End Function > > To use these functions, have something like > Dim stSelect as string = "Select CustomerID, CustomerName, CustomerSales > FROM Customer" > Dim dtCustomer as new Datatable = Filltable(stSelect) > ' Do processing > ' Create parameters > Dim stUpdateText as string = "UPDATE Customers SET CustomerSales = ? WHERE > CustomerID = ?" > Dim lRows as Long = Updatetable(stUpdateText, paramsCustomer,dtCustomer) > '*************************************************************** > > Hope that made sense! Could also have Add and Delete functions. > Are any of you already doing something similiar? > Let me know if you think of anything I may be missing. > Thanks > Vayse > > "Scott M." <s-mar@nospam.nospam> wrote in message I'm trying, but can't seem to get the parameters to pass to the class. See news:evJg%23B6TGHA.5900@tk2msftngp13.phx.gbl... > How about taking this one step further and making those functions part of > a stand-alone class and violla! You now have your own custom data class. > my other thread above - Passing Parameter Collections. If I get that working, I'll have my class. I'll post it here when I get it working. Vayse "Scott M." <s-mar@nospam.nospam> wrote in message Working version now atnews:evJg%23B6TGHA.5900@tk2msftngp13.phx.gbl... > How about taking this one step further and making those functions part of > a stand-alone class and violla! You now have your own custom data class. > http://h1.ripway.com/vayse/DataClass/ Thats a working oleDB example, with a sample database. Vayse Vayse,
I assume it is not Ado which is to ADONET as a car like a plane.(all are to transport). If you want this nicely done, than you can open a component instead of a form. You can than even do it draging, but as well in code. By instance the Idisposable implementation is than by instance already coded for you. I hope this helps, Cor Show quote "Vayse" <nospam@microsoft.com> schreef in bericht news:OW3Uvv5TGHA.5332@tk2msftngp13.phx.gbl... >I don't know about you, but I'm use similiar code again and again to update >my Datatables. So I just thought of something - shouldn't I just put all >the update code in one place? > I don't have access to VS2005 on this PC, but I was thinking of something > along these lines > > '*************************************************************** > Function FillTable(stSQL as string) as Datatable > ' Open Connection > ' Create data adapter > ' Fill Datatable > ' Close connection > End Function > > Function UpdateTable(stCommandText as string, Params as Parameters, > dtUpdate as Datatable) as long > 'Open Connection > 'Create data adapter > 'Create Updatecommand with stCommandText and the parameters collection > 'Have the adapter run the command > ' Close connection > 'Return number of rows updated > End Function > > To use these functions, have something like > Dim stSelect as string = "Select CustomerID, CustomerName, CustomerSales > FROM Customer" > Dim dtCustomer as new Datatable = Filltable(stSelect) > ' Do processing > ' Create parameters > Dim stUpdateText as string = "UPDATE Customers SET CustomerSales = ? WHERE > CustomerID = ?" > Dim lRows as Long = Updatetable(stUpdateText, paramsCustomer,dtCustomer) > '*************************************************************** > > Hope that made sense! Could also have Add and Delete functions. > Are any of you already doing something similiar? > Let me know if you think of anything I may be missing. > Thanks > Vayse > > Of course, adonet. :)
Show quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message news:uZ3Px09TGHA.1576@tk2msftngp13.phx.gbl... > Vayse, > > I assume it is not Ado which is to ADONET as a car like a plane.(all are > to transport). > > If you want this nicely done, than you can open a component instead of a > form. You can than even do it draging, but as well in code. By instance > the Idisposable implementation is than by instance already coded for you. > > I hope this helps, > > Cor > > "Vayse" <nospam@microsoft.com> schreef in bericht > news:OW3Uvv5TGHA.5332@tk2msftngp13.phx.gbl... >>I don't know about you, but I'm use similiar code again and again to >>update my Datatables. So I just thought of something - shouldn't I just >>put all the update code in one place? >> I don't have access to VS2005 on this PC, but I was thinking of something >> along these lines >> >> '*************************************************************** >> Function FillTable(stSQL as string) as Datatable >> ' Open Connection >> ' Create data adapter >> ' Fill Datatable >> ' Close connection >> End Function >> >> Function UpdateTable(stCommandText as string, Params as Parameters, >> dtUpdate as Datatable) as long >> 'Open Connection >> 'Create data adapter >> 'Create Updatecommand with stCommandText and the parameters collection >> 'Have the adapter run the command >> ' Close connection >> 'Return number of rows updated >> End Function >> >> To use these functions, have something like >> Dim stSelect as string = "Select CustomerID, CustomerName, CustomerSales >> FROM Customer" >> Dim dtCustomer as new Datatable = Filltable(stSelect) >> ' Do processing >> ' Create parameters >> Dim stUpdateText as string = "UPDATE Customers SET CustomerSales = ? >> WHERE CustomerID = ?" >> Dim lRows as Long = Updatetable(stUpdateText, paramsCustomer,dtCustomer) >> '*************************************************************** >> >> Hope that made sense! Could also have Add and Delete functions. >> Are any of you already doing something similiar? >> Let me know if you think of anything I may be missing. >> Thanks >> Vayse >> >> > > Vayse,
You also might check into some code generation to automate the process. http://www.mygenerationsoftware.com "Vayse" <nospam@microsoft.com> wrote in message <snip>news:OW3Uvv5TGHA.5332@tk2msftngp13.phx.gbl... >I don't know about you, but I'm use similiar code again and again to update >my Datatables. So I just thought of something - shouldn't I just put all >the update code in one place? > I don't have access to VS2005 on this PC, but I was thinking of something > along these lines > Show quote > > Hope that made sense! Could also have Add and Delete functions. > Are any of you already doing something similiar? > Let me know if you think of anything I may be missing. > Thanks > Vayse > > |
|||||||||||||||||||||||