  windows form

Dim rec As Integer




    Dim ds As New DataSet
    Dim str As String = "select RegionID,RegionDescription from Region "
    Dim dp As SqlClient.SqlDataAdapter
    Dim cmd As New SqlClient.SqlCommand


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        conn.Open()


        Dim dp As New SqlClient.SqlDataAdapter(str, conn)
        dp.Fill(ds, "Region")


        conn.Close()
       

        TextBox1.Text = ds.Tables("Region").Rows(0).Item(0)
        TextBox2.Text = ds.Tables("Region").Rows(0).Item(1)

        TextBox1.DataBindings.Add("Text", ds, "Region.RegionID")

        TextBox2.DataBindings.Add("Text", ds, "Region.RegionDescription")



        Call viewRecord()


    End Sub

          السجل السابق هنا 


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        rec = rec - 1

        If rec < 0 Then
            MsgBox("لا توجد سجلات للأنتقال إليها")
            rec = 0
            Exit Sub
        Else
            Call viewRecord()
        End If

    End Sub

     ألسجل الاول هنا

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        rec = 0
        Call ViewRecord()

    End Sub
             
           ألسجل التالي هنا

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        rec = rec + 1

        If rec > ds.Tables("Region").Rows.Count - 1 Then
            MsgBox("لا توجد سجلات للأنتقال إليها")
            rec = ds.Tables("Region").Rows.Count - 1
            Exit Sub
        Else
            Call viewRecord()
        End If

    End Sub

         label  الذي يعرض فيه ألسجل الحالي

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        rec = ds.Tables("Region").Rows.Count - 1
        Call ViewRecord()
    End Sub
    Private Sub viewRecord()

        TextBox1.Text = ds.Tables("Region").Rows(rec).Item(0)
        TextBox2.Text = ds.Tables("Region").Rows(rec).Item(1)

        Label3.Text = rec & Space(2) & "of" & Space(2) & ds.Tables("Region").Rows.Count

    End Sub
              
                  زر ألمسح 

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        Me.BindingContext(ds, "Region").EndCurrentEdit()
        Me.BindingContext(ds, "Region").AddNew()

    End Sub

    Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub


                      زر إضـــافة هنا  

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        cmd.Connection = conn


        cmd.CommandType = CommandType.Text


        cmd.CommandText = "INSERT INTO Region(RegionID,RegionDescription ) values ('" & TextBox1.Text & "','" & TextBox2.Text & "') "


        conn.Open()


       cmd.ExecuteNonQuery()


        conn.Close()

        MsgBox("تمت عملية الاضافة والحفظ في قاعدة البيانات بنجاح")


    End Sub

           زر التحديث والمشكلة توجد هنا 

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        conn.Open()
        Try

            TextBox1.Update()
            TextBox2.Update()

        Catch eUpdate As System.Exception


            System.Windows.Forms.MessageBox.Show(eUpdate.Message)
        End Try
        Me.ds.AcceptChanges()
        conn.Close()
        Call viewRecord()
        

    End Sub


    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub
End Class
