Hi everyone,
I executed a stored procedure to fill a datatable (function 1). Then I bind the table to a datagrid that shows on a form (function 2). All is ok...
But how can I limit the amount of columns in the datagridview. Not is showing all the fields the sp retrieves. Say I just want to see two columns (say: ContractNo & Balance), how can I achieve this (without adjusting the sp)?
Pampers![[afro] [afro] [afro]](/data/assets/smilies/afro.gif)
Keeping it simple can be complicated
I executed a stored procedure to fill a datatable (function 1). Then I bind the table to a datagrid that shows on a form (function 2). All is ok...
But how can I limit the amount of columns in the datagridview. Not is showing all the fields the sp retrieves. Say I just want to see two columns (say: ContractNo & Balance), how can I achieve this (without adjusting the sp)?
Code:
Private Function GetBalance(ByVal ContractNo As String) As DataTable
'Function (1)
'Execute Stored Procedure, Fill DataTable
'
Try
NewConnection()
OpenConnection()
strSQL = ("uspBalanceGet")
InitializeCommand()
AddParameter("@ContractNo", OleDbType.VarChar, 50, ContractNo)
objDataTable = New DataTable("tblHkContractPay")
objDataAdapter = New OleDbDataAdapter(objCommand)
objDataAdapter.Fill(objDataTable)
GetBalance = objDataTable
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
Code:
Private Sub BindBalanceData()
'Function (2)
'Bind DataTable to DataGrid
'
Try
GetBalance(cboContract.Text)
Me.dtgBalance.DataSource = objDataTable
Catch ex As Exception
MsgBox(ex.ToString)
Finally
'Clean Up
objCommand = Nothing
objDataTable = Nothing
objDataAdapter = Nothing
End Try
End Sub
Pampers
![[afro] [afro] [afro]](/data/assets/smilies/afro.gif)
Keeping it simple can be complicated