Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dataset scroll through records and bind to textbox's on form

Status
Not open for further replies.

696796

Programmer
Aug 3, 2004
218
GB
Hi i have created a dataset of users as shown below:-
Code:
    Public Sub createDataset()
        Dim ds As New DataSet("Users")

        Dim strConn, strSQL As String
        strConn = carDba.getCn

        strSQL = "SELECT UserId, LoginName, LoginPassword, userLevelId, fullName " & _
        "FROM tblUser"
        Dim da As New OleDbDataAdapter(strSQL, strConn)
        da.Fill(ds, "Users")

    End Sub
Pretty sure that will fill "Users" with all the records from tblUSer.

Now my question is, how can i make use of this on my form - i want to bind each selected item to either a textbox or combo on the form...

Secondaly i need to create buttons to scroll left and right through the recordset as a method of viewing each record...

Any help is much apreciated,

al
 
Here is how i bind the field 'UserId' to the textbox 'txtUserId':
Code:
        Me.UserId.DataBindings.Clear()
        Me.UserId.DataBindings.Add(New Binding("Text", <dataset_name>, "<table_name>.UserId"))
<dataset_name> is the ds
<table_name> is the Users

To navigate:
Code:
        Dim baseN As BindingManagerBase = Me.BindingContext.Item(<dataset_name>, "<table_name>")
        baseN.Position [COLOR=red]???[/color]
. Forwards: ??? should be =+1
. Backwards: ??? should be -=1
. Goto first: ??? should be =0
. Goto Last: ??? should be =<dataset_name>.Tables.Item("<table_name>").Rows.Count - 1

 
Hi, i tried using your method - couldn't get it to work

I have tried this and it also doent work as it says object reference not instance of object on the top line:-

Code:
    Private Sub NavigateRecords()

        txtUsername.Text = ds.Tables("Users").Rows(inc).Item("LoginName")
        txtPassword.Text = ds.Tables("Users").Rows(inc).Item(2)
        txtFullName = ds.Tables("Users").Rows(inc).Item(3)


    End Sub

I am filling the dataset using this:-

Code:
Private Sub frmUserData_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As New DataSet("Users")

        Dim strSQL As String
        Dim conn As OleDbConnection = carDba.getCn

        strSQL = "SELECT UserId, LoginName, LoginPassword, userLevelId, fullName " & _
        "FROM tblUser"
        Dim da As New OleDbDataAdapter(strSQL, conn)
        da.Fill(ds, "Users")

        'txtUsername.Text = ds.Tables("UserId").Rows(0).Item(2)

        MaxRows = ds.Tables("Users").Rows.Count
        inc = -1
    End Sub

And navigating through the records like this:- (which doesnt work)

Code:
    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If inc <> MaxRows - 1 Then
            inc = inc + 1
            NavigateRecords()
        Else
            MsgBox("No More Rows")
        End If
    End Sub

Anyone see the error in my ways?....

Alex
 
make the dataset belong to the whole form,, not just the _Load event.

move the "Dim ds" statement the the top of the class, just after the line that says "Public Class frmUserData"

should work fine then.

mr s. <;)

 
Don't suppose you can see how i can get the first record to display on load - at the moment when the form opens none of the boxes are filled until i use the next button(then the first record appears)

A;l
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top