locked
Dynamically changing DataAdapter.Fill SQL statement on WPF form. RRS feed

  • Question

  • I've successfully recreated a form very similar to the form in this walkthough: http://msdn.microsoft.com/en-us/library/dd547149%28VS.100%29.aspx.  I can successfully click on the next, back, and save buttons - everything functions as expected.  But I need to filter the data dynamically based on a user entered value at run time.  Instead of "SELECT [all of my fields] FROM tPeople", I need "SELECT [all of my fields] FROM tPeople WHERE ID = 586".  I need to be able to change that 586 dynamically and have the form populated with the data in that record so the user can edit data.  I've tried building that second SQL statement (sSQL) and then change the code to

    DsPersonstPersonsTableAdapter = New WpfApplication1.dsPersonsTableAdapters.tPersonsTableAdapter(sSQL)

    VS reports that there are too many arguments and is only happy when there are no arguments in the above line.   

    My dataset only references one table for a SQL CE database.  It seems that this should be super simple. 

    Sunday, June 12, 2011 10:14 PM

Answers

  • I got it.  I created a new query in the dataset designer called FillByID, it has a parameter

     

    New code:

    DsPersonstPersonsTableAdapter = New WpfApplication1.dsPersonsTableAdapters.tPersonsTableAdapter()

    DsPersonstPersonsTableAdapter.FillByID(DsPersons.tPersons, ListView1.SelectedItem(0))

    • Proposed as answer by Yves.Z Wednesday, June 15, 2011 8:19 AM
    • Marked as answer by Yves.Z Friday, June 17, 2011 5:41 AM
    Sunday, June 12, 2011 11:39 PM

All replies

  • I got it.  I created a new query in the dataset designer called FillByID, it has a parameter

     

    New code:

    DsPersonstPersonsTableAdapter = New WpfApplication1.dsPersonsTableAdapters.tPersonsTableAdapter()

    DsPersonstPersonsTableAdapter.FillByID(DsPersons.tPersons, ListView1.SelectedItem(0))

    • Proposed as answer by Yves.Z Wednesday, June 15, 2011 8:19 AM
    • Marked as answer by Yves.Z Friday, June 17, 2011 5:41 AM
    Sunday, June 12, 2011 11:39 PM
  • Thank you for sharing experience here.

    Have a nice day!


    Yves Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 17, 2011 5:41 AM