-
Jan 27th, 2015, 02:43 PM
#1
Thread Starter
Member
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!
-
Jan 27th, 2015, 05:07 PM
#2
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")
-
Jan 27th, 2015, 06:02 PM
#3
Thread Starter
Member
Re: Multiple database records on multiple textboxes
Thanks ! I'll look into it!
-
Jan 29th, 2015, 04:56 AM
#4
Thread Starter
Member
Re: Multiple database records on multiple textboxes
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
-
Jan 29th, 2015, 04:42 AM
#5
Thread Starter
Member
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
-
Jan 29th, 2015, 07:47 AM
#6
Frenzied Member
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?
-
Jan 29th, 2015, 08:11 AM
#7
Thread Starter
Member
Re: Multiple database records on multiple textboxes
Originally Posted by CoachBarker
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;
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|