Help with vb.net 03 and ado.net

  • 11 years ago
    I am new here and rookie programer.  I am totally lost and cannot find exactly what I am looking for.  Here is my problem.  I have a database (access) and a table for users accounts in the database.  I have a form to edit the user accounts but cannot get it to work properly.  The form has a listbox to the left that displays usernames and then textboxes to the right that contains the information about the user.  I am able to get the usernames to populate in the listbox, but I cannot get the textboxes to display the correct information and be able to update, add or delete users.  Can somebody please help?



  • 11 years ago
    Could you please write your code to know where the problem is?
  • 11 years ago
    Thats the thing, I dont know exactly how to write it.  Its not that I have an error in the code, I just dont know exactly what I need.  I know I need a connection, dataset, and datadpator.  But I dont know how to sync the textboxes with listbox and the listbox with the database so the information can be updated.

  • 11 years ago
    Here's what you do.  You bind the ListBox to the DataTable so that it displays the user names, e.g.
    myListBox.DisplayMember = "UserName"
    myListBox.ValueMember = "ID"
    myListBox.DataSource = myDataTable

    Now you need to bind the other controls to the same data source, e.g.
    myTextBox1.DataBindings.Add("Text", myDataTable, "FirstName")
    myTextBox2.DataBindings.Add("Text", myDataTable, "LastName")
    This binds the Text properties of the two TextBoxes to the FirstName and LastName columns of the same table to which the ListBox is bound.  That means that when you make a selection in the ListBox the contents of the TextBoxes will be updated to display the corresponding fields.

  • 11 years ago
    Thank you.  So do I need to put any code in the listbox's selectedvaluechanged event?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill