Windows Forms - Select and Update Problems


  • I am trying to create a form to manage customer info.

    The database I am using is a SQL Express database I created in Visual Studio.  "localDB.sdf"

    On the left is a list box which I want to set the Display Member to a concatination of the customer's first name and last name, pulled from the "FirstName" column and "LastName" column in the database. The Key ID, "ID" column,  should be assigned to the listbox's Value Member.

    When a name is selected in the listbox, it should populate all of the customer's info in textboxes to the right.

    I have three buttons: New, Update, and Cancel.

    The New button should insert a new row into the database with all blank fields, except the Key ID which auto-increments. It should then reload the listbox to show the blank field and obviously all the textbox will load blank too.

    The Update button should obviously update the database according to Key ID from the Value Member of the listbox based on the selected index. The list box should the be reloaded to show the new first and last name concatinated together.

    I have tried using the objects Visual Studio auto generates. The objects work great in doing everything I want, except the tableAdapter does not update back to the database when using the tableAdapter.Update(dataset.tableName) method.

    So I tried using SqlCe command. I can update the database this way, but I cannot load queried info into the listbox, nor have the IndexSelectedChanged to load the info into all the textboxes based on the selected option in the listbox.

    I have also tried Linq but can not get that to work at all.

    What would be the best way to do this??

    Friday, November 30, 2012 2:00 AM

All replies

  • Hi Paul,

    Welcome to the MSDN forum.

    Do you use Entity Framework? If so, I am not sure why you use tableAdapter to update the tables.

    Have a nice day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Monday, December 03, 2012 3:03 AM