Results 1 to 7 of 7

Thread: Multiple database records on multiple textboxes

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    39

    Multiple database records on multiple textboxes

    Information:

    Windows 8
    Visual Studio 2013
    Microsoft Acsess Database

    ---

    Hello everyone!

    I only started programming on vb.net 5 days ago, my work is to manipulate a Database using only Visual Studio ( deleting, adding, viewing and displaying records ), Its for a school project.

    I did it very nicely my professor was impressed, but now he doesn't want me to display the records on a DataGrid, instead, he wants me to display the records on multiple textboxes and im completely lost on that!

    I have a textbox where i type the ID of the person i want, then press a " Search" button and it shows on the data grid the information regarding that person ( name, security level etc )

    I have to do the same but this time each piece of information goes into separate textboxes!

    The name has to show up on its specific textbox, the security level as well, you get the point. I know how to do this in DataGrid but i have no idea how to send each row?? into it's own textbox.

    Any guidance would be greatly appreciated!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Multiple database records on multiple textboxes

    If you've done it correctly, the code to accomplish the searching shouldn't change. If you're using a DataGridView, what should be happening is that you use a data adapter or table adapter to populate a DataTable, bind that to a BindingSource and then bind that to the grid. When you search, you then use the Find and Position members of the BindingSource to select the appropriate record. If you want to use TextBoxes instead of a DataGridView then the searching part is exactly the same and all that changes is the binding part. You can set up the binding in the designer if you're using a typed DataSet or you can do it in code. If you do it in code, binding to a grid would look like this:
    Code:
    myDataGridView.DataSource = myBindingSource
    while binding to TextBoxes would look like this:
    Code:
    givenNameTextBox.DataBindings.Add("Text", myBindingSource, "GivenName")
    familyNameTextBox.DataBindings.Add("Text", myBindingSource, "FamilyName")

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    39

    Re: Multiple database records on multiple textboxes

    Thanks ! I'll look into it!

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    39

    Re: Multiple database records on multiple textboxes

    Name:  form.jpg
Views: 186
Size:  18.4 KB

    After typing the ID on the textbox and pressing " SEARCH " it will read into the database and display the records for that ID in the textboxes above.

    I managed to do that quite easy in a DataGrid but now i need them to show in their right place and im lost on that

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    39

    Re: Multiple database records on multiple textboxes

    Im a bit confused, this is all so new to me im a little overwhelmed.

    Im not sure if i explained my self correctly but you said "" ... is that you use a data adapter or table adapter to populate a DataTable, bind that to a BindingSource and then bind that to the grid ""

    Is this what i should of done with the DataGrid in the first place? OR is this what i should do now to separate the records into their own assigned textbox?

    With just one click of the " search " button, i have to display the contents of that persons information into 3 diferent textboxes

  6. #6
    Frenzied Member CoachBarker's Avatar
    Join Date
    Aug 2007
    Location
    Central NY State
    Posts
    1,121

    Re: Multiple database records on multiple textboxes

    show the code you use to load your datagridview so we can see how you are doing it. Also what is the name of your 2 textboxes?
    Thanks
    CoachBarker

    Code Bank Contribution
    Login/Manage Users/Navigate Records
    VB.Net | C#

    Helpful Links: VB.net Tutorial | C Sharp Tutorial | SQL Basics

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2015
    Posts
    39

    Re: Multiple database records on multiple textboxes

    Quote Originally Posted by CoachBarker View Post
    show the code you use to load your datagridview so we can see how you are doing it. Also what is the name of your 2 textboxes?

    Private Sub btnPesquisar_Click(sender As Object, e As EventArgs) Handles btnPesquisar.Click
    con.Open()
    Dim str As String

    str = "select id, nome, niveldeacesso from TesteDatabase where id ='" & txtfind.Text & "'"
    da = New OleDb.OleDbDataAdapter(str, con)

    ds = New DataSet
    da.Fill(ds, "teste")

    DataGridView1.DataSource = ds
    DataGridView1.DataMember = "Teste"

    con.Close()


    This is how i fill the DataGrid, and each time i do a search it works perfectly giving me back the records for the matching ID as you can see in this picture;

    Name:  form1.jpg
Views: 169
Size:  15.0 KB

    what i really want here is to do the exact same search but instead of viewing the results on the DataGrid, it will split the NAME, ID and ACESS LEVEL into their own textboxes above ( Shown as empty in the picture )

    name of the textboxes i want to fill:

    txtname
    txtid
    txtacess
    Last edited by GiovanniRoberts; Jan 29th, 2015 at 08:15 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width