emaduddeen
Well-known member
- Joined
- May 5, 2010
- Messages
- 171
- Location
- Lowell, MA & Occasionally Indonesia
- Programming Experience
- Beginner
Hi Everyone,
Should I let a DataAdapter open a connection multiple times?
I'm trying to figure out the best way to handle this:
My form contains a DataGrid and many TextBox controls and everytime the user moves the highlight bar on the DataGrid I display detail data representing the information in the DataGrid.
Every time the highlight bar is moved on the DataGrid this code is executed which connects to the database every time it's moved. Is this the best way to handle a situation like this? Would it be better to connect to the database once and leave the connection open and just to clear out the DataAdapter and somehow refill it instead? If it's best to clear it out and refill it, can you show me some code examples on how to do this?
Here's the code:
The code works ok but I'm just looking for the best way to do it.
Thanks.
Truly,
Emad
Should I let a DataAdapter open a connection multiple times?
I'm trying to figure out the best way to handle this:
My form contains a DataGrid and many TextBox controls and everytime the user moves the highlight bar on the DataGrid I display detail data representing the information in the DataGrid.
Every time the highlight bar is moved on the DataGrid this code is executed which connects to the database every time it's moved. Is this the best way to handle a situation like this? Would it be better to connect to the database once and leave the connection open and just to clear out the DataAdapter and somehow refill it instead? If it's best to clear it out and refill it, can you show me some code examples on how to do this?
Here's the code:
VB.NET:
' Create the data adapter for the Customer Details.
' This data adapter will be used when displaying the Customer Details.
'---------------------------------------------------------------------
objDataAdapterParentDetails = New SqlDataAdapter(strSQL, _
(BuildConnectionString("EMAD-PC\SQLEXPRESS", _
"EmadElectronics", _
strUser, _
strPassword)))
The code works ok but I'm just looking for the best way to do it.
Thanks.
Truly,
Emad