R
Ryan
How do I add custom paging to the following code?
Public Class Form2
Private PageCount As Integer
Private maxRec As Integer
Private pageSize As Integer
Private currentPage As Integer
Private recNo As Integer
Private ds As New DataSet
Private dt As New DataTable
Private da As OracleDataAdapter
Private dv As DataView
Private dtTemp As DataTable
Private myBindingSource As BindingSource
Private myDataSet As DataSet
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
LoadData("select * from Contact")
End Sub
Private Sub LoadData(ByVal str As String)
Try
Dim myCMD As New OracleCommand()
gsCnnString = CreateConnection()
Using objConn As New OracleConnection(gsCnnString)
Dim objCmd As New OracleCommand()
objCmd.Connection = objConn
objCmd.CommandText = str
objCmd.CommandType = CommandType.Text
Try
Dim oAdapter As OracleDataAdapter
oAdapter = New OracleDataAdapter(str, objConn)
myDataSet = New DataSet()
oAdapter.Fill(myDataSet)
myBindingSource = New BindingSource()
myBindingSource.DataSource = myDataSet
myBindingSource.DataMember = myDataSet.Tables(0).TableName
DataGridView1.DataSource = myBindingSource
Catch ex As Exception
objCmd.Connection.Dispose()
objConn.Close()
MessageBox.Show("Exception: {0}", ex.ToString())
End Try
objConn.Close()
End Using
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Information, "LoadData")
End Try
End Sub
Public Function CreateConnection() As String
gsServerNameFromRes = gsServerNameFromRes
gsUserIDFromRes = gsUserIDFromRes
gsPasswordFromRes = gsPasswordFromRes
gsServerNameFromRes = "MyTNSName"
gsUserIDFromRes = "MyUserID"
gsPasswordFromRes = "MyPassword" '
gsCnnString = "Data Source=" & gsServerNameFromRes & _
";User Id=" & gsUserIDFromRes & _
";Password=" & gsPasswordFromRes
Return gsCnnString
End Function
Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFilter.Click
Dim sFilter As String = TextBox1.Text
myBindingSource.Filter = "FIRSTNAME = '" & sFilter & "'" End Sub
End Class
Public Class Form2
Private PageCount As Integer
Private maxRec As Integer
Private pageSize As Integer
Private currentPage As Integer
Private recNo As Integer
Private ds As New DataSet
Private dt As New DataTable
Private da As OracleDataAdapter
Private dv As DataView
Private dtTemp As DataTable
Private myBindingSource As BindingSource
Private myDataSet As DataSet
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
LoadData("select * from Contact")
End Sub
Private Sub LoadData(ByVal str As String)
Try
Dim myCMD As New OracleCommand()
gsCnnString = CreateConnection()
Using objConn As New OracleConnection(gsCnnString)
Dim objCmd As New OracleCommand()
objCmd.Connection = objConn
objCmd.CommandText = str
objCmd.CommandType = CommandType.Text
Try
Dim oAdapter As OracleDataAdapter
oAdapter = New OracleDataAdapter(str, objConn)
myDataSet = New DataSet()
oAdapter.Fill(myDataSet)
myBindingSource = New BindingSource()
myBindingSource.DataSource = myDataSet
myBindingSource.DataMember = myDataSet.Tables(0).TableName
DataGridView1.DataSource = myBindingSource
Catch ex As Exception
objCmd.Connection.Dispose()
objConn.Close()
MessageBox.Show("Exception: {0}", ex.ToString())
End Try
objConn.Close()
End Using
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Information, "LoadData")
End Try
End Sub
Public Function CreateConnection() As String
gsServerNameFromRes = gsServerNameFromRes
gsUserIDFromRes = gsUserIDFromRes
gsPasswordFromRes = gsPasswordFromRes
gsServerNameFromRes = "MyTNSName"
gsUserIDFromRes = "MyUserID"
gsPasswordFromRes = "MyPassword" '
gsCnnString = "Data Source=" & gsServerNameFromRes & _
";User Id=" & gsUserIDFromRes & _
";Password=" & gsPasswordFromRes
Return gsCnnString
End Function
Private Sub btnFilter_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFilter.Click
Dim sFilter As String = TextBox1.Text
myBindingSource.Filter = "FIRSTNAME = '" & sFilter & "'" End Sub
End Class