Hi
How navigate record in Datatable like ADO.MoveNext & ADO.MovePervios and show current record in datagride by diferent color?
Thanks
Hi
How navigate record in Datatable like ADO.MoveNext & ADO.MovePervios and show current record in datagride by diferent color?
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raj KumarPosted Jan 1, 2008, 7:29 AM
try this code change connection string.
Imports System.Data.SqlClient
Public Class RecordNavigation
Inherits System.Windows.Forms.Form
#Region "InitializeEnvironment Variables"
''''''''''''''''' Initialize the Environment
Variables '''''''''''''''''''''''''''''''''''''''''''''''''
''''''
Public I As Integer
Public SqlCon As New SqlConnection("Data Source=srins;
Initial Catalog=VET; User ID=sa; Password=007;")
Public dataTable As New dataTable()
Public dataSet As New dataSet()
Public DR As DataRow
Public RowCount As Integer
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''
#End Region
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form
Designer.
InitializeComponent()
'Add any initialization after the
InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal
disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the
Private Sub
Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btn_Next As
System.Windows.Forms.Button
Friend WithEvents btn_Previous As
System.Windows.Forms.Button
Friend WithEvents btn_MoveFirst As
System.Windows.Forms.Button
Friend WithEvents btn_MoveLast As
System.Windows.Forms.Button
Friend WithEvents txt_OwnerID As
System.Windows.Forms.TextBox
InitializeComponent()
Me.txt_OwnerID = New System.Windows.Forms.TextBox()
Me.btn_Next = New System.Windows.Forms.Button()
Me.btn_Previous = New System.Windows.Forms.Button()
Me.btn_MoveFirst = New System.Windows.Forms.Button
()
Me.btn_MoveLast = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'txt_OwnerID
'
Me.txt_OwnerID.Location = New System.Drawing.Point
(72, 56)
Me.txt_OwnerID.Name = "txt_OwnerID"
Me.txt_OwnerID.Size = New System.Drawing.Size(160,
20)
Me.txt_OwnerID.TabIndex = 0
Me.txt_OwnerID.Text = ""
'
'btn_Next
'
Me.btn_Next.Location = New System.Drawing.Point
(56, 96)
Me.btn_Next.Name = "btn_Next"
Me.btn_Next.Size = New System.Drawing.Size(72, 24)
Me.btn_Next.TabIndex = 1
Me.btn_Next.Text = "Next >>"
'
'btn_Previous
'
Me.btn_Previous.Location = New System.Drawing.Point
(152, 96)
Me.btn_Previous.Name = "btn_Previous"
Me.btn_Previous.Size = New System.Drawing.Size(80,
24)
Me.btn_Previous.TabIndex = 2
Me.btn_Previous.Text = "<< Previous "
'
'btn_MoveFirst
'
Me.btn_MoveFirst.Location = New
System.Drawing.Point(56, 128)
Me.btn_MoveFirst.Name = "btn_MoveFirst"
Me.btn_MoveFirst.Size = New System.Drawing.Size
(72, 24)
Me.btn_MoveFirst.TabIndex = 3
Me.btn_MoveFirst.Text = "Move First"
'
'btn_MoveLast
'
Me.btn_MoveLast.Location = New System.Drawing.Point
(152, 128)
Me.btn_MoveLast.Name = "btn_MoveLast"
Me.btn_MoveLast.Size = New System.Drawing.Size(80,
24)
Me.btn_MoveLast.TabIndex = 4
Me.btn_MoveLast.Text = "Move Last"
'
'RecordNavigation
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5,
13)
Me.ClientSize = New System.Drawing.Size(392, 253)
Me.Controls.AddRange(New
System.Windows.Forms.Control() {Me.btn_MoveLast,
Me.btn_MoveFirst, Me.btn_Previous, Me.btn_Next,
Me.txt_OwnerID})
Me.Name = "RecordNavigation"
Me.Text = "RecordNavigation"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub RecordNavigation_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
' just get the DataAdapter
Try
I = 0
Dim oComd As New SqlCommand()
oComd.CommandText = "TestProcedure "
oComd.CommandType = CommandType.StoredProcedure
oComd.Parameters.Add("@OwnerID",
Convert.ToInt64(304442788964445))
oComd.Connection = SqlCon
Dim SqlAdapter As New SqlDataAdapter(oComd)
SqlAdapter.Fill(dataTable)
DR = dataTable.Rows(I)
txt_OwnerID.Text = DR(0)
RowCount = dataTable.Rows.Count
Catch ee As SqlException
MessageBox.Show(ee.ToString())
End Try
End Sub
Private Sub btn_Next_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btn_Next.Click
If I = RowCount - 1 Then Return
I = I + 1
DR = dataTable.Rows(I)
txt_OwnerID.Text = DR(0)
End Sub
Private Sub btn_Previous_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btn_Previous.Click
If I = -1 Or I = 0 Then
I = 0
Return
End If
I = I - 1
DR = dataTable.Rows(I)
txt_OwnerID.Text = DR(0)
End Sub
Private Sub btn_MoveFirst_Click(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
btn_MoveFirst.Click
I = 0
DR = dataTable.Rows(I)
txt_OwnerID.Text = DR(0)
End Sub
Private Sub btn_MoveLast_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btn_MoveLast.Click
I = RowCount - 1
DR = dataTable.Rows(I)
txt_OwnerID.Text = DR(0)
End Sub
End Class