Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with VB.Net and MySQL: Next/Previous Record

$
0
0
Hi, I am developing a program for my uncle where I am storing his clients data using MySQL in a database. I have created a basic form where the data from the database is displayed in different textboxes presenting each field (e.g. company name or address). I have been able to connect to the database so far and can insert data from the form to the database but I am struggling to understand how to show different records. I have two buttons, previous and next where clicking them will do either go to the previous record or next one from the database. I have tried using a WHERE statement but it only then displays the next record and will just keep showing that particular one and not progress to the other one. I have looked for help on the internet but have not found much.

 
Dim dbCon As MySqlConnection
        Dim strQuery As String
        Dim SQLCmd As MySqlCommand
        Dim DR As MySqlDataReader


        dbCon = New MySqlConnection("server=*****; Database=*******; user id=******; password=******;")

        Try

            strQuery = "SELECT client.CompanyID, client.street, client.county, client.CompanyName, client.ClientForename, client.ClientSurname, client.PhoneNumber, client.town, client.postcode " & _
            "FROM client "


            SQLCmd = New MySqlCommand(strQuery, dbCon)

            dbCon.Open()
            DR = SQLCmd.ExecuteReader
            While DR.Read
                TextBox1.Text = DR.Item("CompanyID")
                TextBox2.Text = DR.Item("CompanyName")
                TextBox3.Text = DR.Item("ClientForename")
                TextBox4.Text = DR.Item("ClientSurname")
                TextBox5.Text = DR.Item("Street")
                TextBox6.Text = DR.Item("Town")
                TextBox7.Text = DR.Item("county")
                TextBox8.Text = DR.Item("postcode")
                TextBox9.Text = DR.Item("PhoneNumber")

            End While

            DR.Close()
            dbCon.Close()

        Catch ex As Exception
            MsgBox("Failure to connect!" & ex.Message)
        End Try

    End Sub 



This just shows my program connecting and displaying the first record. I am not experienced in VB so if my code looks rubbish please suggest ways to make it look better. I would extremely appreciate the help as it has been nagging me for the past few days.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>