cardona
10-06-2006, 03:03 AM
I have 3 datagrids that all get populated when a web page loads, all data required is from the same table (in SQL Server 2000), but for each datagrid I am calling seperate connections to the database
example of 1 of my subs that fill a datagrid
Private Sub sbFillPending()
Dim strSelect As String = "SELECT CurrentStatus,TANumber FROM tblMain WHERE RequestingStaff='" & Me.lblStaff.Text & _
"' AND CurrentStatus<4 AND CurrentStatus>=2"
Try
objConnection.Open()
Catch ex As Exception
Me.lblError.Text = "An error occurred while opening the database, in sbFillPending."
Exit Sub
End Try
'Create a command Object using the passed in parameter strSelect
Dim objResults As New SqlCommand(strSelect, objConnection)
Dim objResults1 As New SqlDataAdapter
' Pass the Select command to the adapter.
objResults1.SelectCommand = objResults
'Use "ds" (declared at top of code page) DataSet to hold information from the worksheet.
ds = Nothing
ds = New DataSet()
' Fill the DataSet with the information from the worksheet.
Try
objResults1.Fill(ds)
Catch ex As Exception
Me.lblError.Text = "An error occurred while filling objResults1, in sbFillPending."
objConnection.Close()
Exit Sub
End Try
' Clean up objects.
objConnection.Close()
Me.dgPending.DataSource = ds
Me.dgPending.DataBind() 'bind the datagrid with the datasource
End Sub
so have 2 more of these for the other two datagrids, each one is slightly different in the 'WHERE' clauses and also the fields that are getting SELECTed vary.
Just been thinking about it, maybe the best idea is to dim each Select statement in the one sub, then dim a sqlcommand each, and run each one while the connection is open. or is it better to have one strSelect dim'ed, and seperate each select with a ';' i.e. "select * from tbl; select * from tbl where field=value; select * where field=another value" and then run that under an sqlCommand. But if you use one strSelect, how do you retrieve the results, to then bind to each datagrid?
any help would be appreciated, but since it is Firday knock-off time for me, you guys can have the weekend to think about it, and come up with the perfect solution :D
cya's Monday!!
example of 1 of my subs that fill a datagrid
Private Sub sbFillPending()
Dim strSelect As String = "SELECT CurrentStatus,TANumber FROM tblMain WHERE RequestingStaff='" & Me.lblStaff.Text & _
"' AND CurrentStatus<4 AND CurrentStatus>=2"
Try
objConnection.Open()
Catch ex As Exception
Me.lblError.Text = "An error occurred while opening the database, in sbFillPending."
Exit Sub
End Try
'Create a command Object using the passed in parameter strSelect
Dim objResults As New SqlCommand(strSelect, objConnection)
Dim objResults1 As New SqlDataAdapter
' Pass the Select command to the adapter.
objResults1.SelectCommand = objResults
'Use "ds" (declared at top of code page) DataSet to hold information from the worksheet.
ds = Nothing
ds = New DataSet()
' Fill the DataSet with the information from the worksheet.
Try
objResults1.Fill(ds)
Catch ex As Exception
Me.lblError.Text = "An error occurred while filling objResults1, in sbFillPending."
objConnection.Close()
Exit Sub
End Try
' Clean up objects.
objConnection.Close()
Me.dgPending.DataSource = ds
Me.dgPending.DataBind() 'bind the datagrid with the datasource
End Sub
so have 2 more of these for the other two datagrids, each one is slightly different in the 'WHERE' clauses and also the fields that are getting SELECTed vary.
Just been thinking about it, maybe the best idea is to dim each Select statement in the one sub, then dim a sqlcommand each, and run each one while the connection is open. or is it better to have one strSelect dim'ed, and seperate each select with a ';' i.e. "select * from tbl; select * from tbl where field=value; select * where field=another value" and then run that under an sqlCommand. But if you use one strSelect, how do you retrieve the results, to then bind to each datagrid?
any help would be appreciated, but since it is Firday knock-off time for me, you guys can have the weekend to think about it, and come up with the perfect solution :D
cya's Monday!!