43 Search Record in MySql DataBase in VB.NET

Code :

Imports MySql.Data.MySqlClient
Public Class Form1
    Dim con As MySqlConnection
    Dim adpt As MySqlDataAdapter
    Dim ds As New DataSet
    Dim i, total As Integer

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        con = New MySqlConnection("server=localhost;database=student;uid=root;password=;SSl Mode=None")
        con.Open()
        adpt = New MySqlDataAdapter("select * from stud", con)
        adpt.Fill(ds, "stud")
        total = ds.Tables("stud").Rows.Count
    End Sub

    Public Sub Show(ByVal pos As Integer)
        If i < total And i >= 0 Then
            TextBox1.Text = ds.Tables("stud").Rows(pos).Item(0)
            TextBox2.Text = ds.Tables("stud").Rows(pos).Item(1)
        Else
            MsgBox("Item Completed")
        End If
    End Sub

    'first
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        i = 0
        Me.Show(i)
    End Sub

    'Next
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        i = i + 1
        Me.Show(i)
    End Sub

    'Previous
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        i = i - 1
        Me.Show(i)
    End Sub

    'Last
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        i = ds.Tables("stud").Rows.Count - 1
        Me.Show(i)
    End Sub
End Class





Output:


Search Record in DataBase



Previous
Next Post »