V
Vili
Hi all
I would like to get some ideas and opinions of my solution for
dataconnection on asp.net 2.0
I have created a class which encapsulates the sqldatasource usage.
With my class one can set select-, insert-, update- and deletecommand
with and without parameters and also get output parameters
Typical usage from code-behind:
I might have one gridview and a detailview on my page.
I fill my gridview like this
I set up my datasources on the top of the code so that they can be
used from all over on that page class
On page load:
myDS = new myDatasource("SELECT id, fname, lname FROM user")
gridview1.datasource = myDS.Datasource ' <- sqldatasource
gridview1.databind
On gridview1.SelectedIndexChange
myDetailDs = new myDatasource("SELECT * FROM WHERE Id = @id")
myDetailDs.SelectParameters.add("Id", gridview1.selectedDatakey)
detailview1.datasource = myDetailDs.datasource
detailview1.databind
All of this works fine but I am still not sure if this is the best way
to go. At the moment all my sql statements are in code-behind and I am
not sure how I could remove all that from to own layer. Maybe create a
separate function for all the statements? Does not sound the perfect
solution.
How does paging on datagrid happen in this case? Can sqldatasource
handle it well or does all the data still stay in viewstate? If so,
how to fix this?
Regards,
Vili
I would like to get some ideas and opinions of my solution for
dataconnection on asp.net 2.0
I have created a class which encapsulates the sqldatasource usage.
With my class one can set select-, insert-, update- and deletecommand
with and without parameters and also get output parameters
Typical usage from code-behind:
I might have one gridview and a detailview on my page.
I fill my gridview like this
I set up my datasources on the top of the code so that they can be
used from all over on that page class
On page load:
myDS = new myDatasource("SELECT id, fname, lname FROM user")
gridview1.datasource = myDS.Datasource ' <- sqldatasource
gridview1.databind
On gridview1.SelectedIndexChange
myDetailDs = new myDatasource("SELECT * FROM WHERE Id = @id")
myDetailDs.SelectParameters.add("Id", gridview1.selectedDatakey)
detailview1.datasource = myDetailDs.datasource
detailview1.databind
All of this works fine but I am still not sure if this is the best way
to go. At the moment all my sql statements are in code-behind and I am
not sure how I could remove all that from to own layer. Maybe create a
separate function for all the statements? Does not sound the perfect
solution.
How does paging on datagrid happen in this case? Can sqldatasource
handle it well or does all the data still stay in viewstate? If so,
how to fix this?
Regards,
Vili