Results 1 to 7 of 7

Thread: navigate through sql records problem

  1. #1
    drpcken is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2004
    Posts
    12
    Reputation
    111

    navigate through sql records problem

    Have a problem and can't put my finger on how to get it to work.

    I'm making a webform, in the webform there are textbox controls. I'll use 3 for this example.

    txtFirstName
    txtMI
    txtLastName

    I also have a SQL table, (connections already created and working) where i have 3 columns: FirstName, MI, LastName. They also have a primary key called RecId which is just an autonumber.

    I have 2 buttons: btnPrev and btnNext. See where I'm going with this? I want to click btnNext and have it put the values of the three columns in sql into the corrosponding 3 textboxes, and when I hit btnNext again, go to the next record, and so forth. When I hit btnPrev i want it to move to the previous record in the database.

    I'm thinking I need to create a dataset holding this information, but getting it from the dataset to the txtboxes is stumping me.

    PLEASE HELP!!! Thank you guys so much!!

  2. #2
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    First, add databindings to the text boxes:

    Code:
    txtMI.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSetName, "MI"))
    To do the previous and next buttons use this code (I also threw in Last and First record code):
    Code:
    'Next:
    Me.BindingContext(DataSetName, "TableName").Position = _
      (Me.BindingContext(DataSetName, "TableName").Position + 1)
    'Previous:
    Me.BindingContext(DataSetName, "TableName").Position = _
      (Me.BindingContext(DataSetName, "TableName").Position - 1)
    'Last:
    Me.BindingContext(DataSetName, "TableName").Position = _
      (Me.objdsDataForm.Tables("TableName").Rows.Count - 1)
    'First:
    Me.BindingContext(objdsDataForm, "TableName").Position = 0
    — Stephen Paszt

  3. #3
    drpcken is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2004
    Posts
    12
    Reputation
    111
    Looks simple enough thank you!

    But where do I add the binding to the txtbox? in the pageload?

    Thanks again!!

  4. #4
    drpcken is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2004
    Posts
    12
    Reputation
    111
    txtMI.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.DataSetName, "MI"))


    Visual Studio doesn't like that line, especially the system.windows.forms.binding, says its not a member.

    Remember I'm using Vb.NET and kinda noobish, I tried importing it, but theres no system.windows namespace

  5. #5
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    The Binding class is a member of the System.Windows.Forms namespace. If you created a WinForm app, you should already have this reference. The 'DataBindings' property for txtMI is also a member of that namespace (as are textboxes, forms, ...).

    Since you are using Visual Studio, you could use the Data Form Wizard which will do all this work for you. Then you can view the code to see how it's done. This is how I learned dataBinding.

    To start the Data Form Wizard: from an existing project click 'File' -> 'Add New Item'; in the dialog select 'Data Form Wizard' and follow the instructions.
    — Stephen Paszt

  6. #6
    drpcken is offline VB.NET Forum Newbie
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Jun 2004
    Posts
    12
    Reputation
    111

    Unhappy

    Everything you said makes perfect sense, but its telling me that my

    me.BindingContext is not a member of ProjectName.WebFormName

    I even tried adding this to my form:

    Imports System.Windows.Forms

    to import the namespace, but it tells me my namespace isn't valid.

    Is something seriously messed up here?

  7. #7
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,502
    Reputation
    308
    I didn't read your very first post very well; you're creating a webForm, I was thinking WinForm. Sorry.

    The standard way to display tables in WebForms is by using a datagrid or repeater to create a table of information.

    If you want to view single records, you could load the dataset into a session variable and keep track of the current record number also with a session variable; increment or decrement the record number with the button event handlers and display that record number.

    I'm not too strong with webForms so I'm not sure of the best method.
    — Stephen Paszt

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking