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