Programming for Everybody: Visual Basic.net: Retrieve data from SQL Server database and navigation Buttons[ with source code ]

Visual Basic.net: Retrieve data from SQL Server database and navigation Buttons[ with source code ]

 



Imports System.Data.SqlClient


Public Class Form2
    Dim table As New DataTable

    Dim index As Integer


    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        loadData(index)

    End Sub
    Public Sub loadData(ByVal position As Integer)

        Dim con1 As New SqlConnection("Data Source=prog-pc;Initial Catalog=d2;Integrated Security=True")
        Dim com1 As New SqlCommand("select id,firstname,lastname,telephone,sum from table1", con1)
       
        Dim adapter As New SqlDataAdapter(com1)

        adapter.Fill(table)


        TextBox1.Text = table.Rows(position)(0).ToString
        TextBox2.Text = table.Rows(position)(1).ToString
        TextBox3.Text = table.Rows(position)(2).ToString
        TextBox4.Text = table.Rows(position)(3).ToString
        TextBox5.Text = table.Rows(position)(4).ToString









    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        index = 0
        loadData(index)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        index += 1
        loadData(index)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        index -= 1
        loadData(index)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        index = table.Rows.Count - 1
        loadData(index)


    End Sub
End Class

No comments:

Post a Comment