Home All Groups Group Topic Archive Search About
Author
24 Mar 2006 11:37 PM
Vayse
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

Author
25 Mar 2006 12:11 AM
Scott M.
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
>
>
Author
28 Mar 2006 10:47 AM
Vayse
"Scott M." <s-mar@nospam.nospam> wrote in message
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.
>
I'm trying, but can't seem to get the parameters to pass to the class. See
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
Author
28 Mar 2006 5:07 PM
Vayse
"Scott M." <s-mar@nospam.nospam> wrote in message
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.
>

Working version now at
http://h1.ripway.com/vayse/DataClass/

Thats a working oleDB example, with a sample database.

Vayse
Author
25 Mar 2006 7:26 AM
Cor Ligthert [MVP]
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
>
>
Author
26 Mar 2006 5:13 PM
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
>>
>>
>
>
Author
25 Mar 2006 5:22 PM
Matt Noonan
Vayse,

You also might check into some code generation to automate the process.

http://www.mygenerationsoftware.com


--
Matt Noonan
EasyObjects.NET: The O/RM for the Enterprise Library
http://www.easyobjects.net


"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
>
<snip>
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
>
>

AddThis Social Bookmark Button