DaveCox

Hi,

I am currently working on a project in which i've used the DataSet (.xsd) things (are they controls objects ). I then bind these to a GridView via the DataSource associated with the GridView. Easy peasy.

This works fine so far, as where I have used this method I have only needed to show all rows from the tables i'm using (SELECT * FROM nef_groups).

Now however, I need to return only some records (SELECT * FROM nef_
groups WHERE group_key = 2). This value will come from a querystring.

How would I pass this querystring value into the DataSet query Is there a better way to achieve what I want It's fairly important that the rows returned end up in a GridView to maintain continuity, where the column headings can be used for sorting etc.

Thanks for any help,
Dave.



Re: Visual C# General Passing arguments to a .xsd (Dataset)

Rory (Clissold Solutions)

An xsd is just a helpful thing that Visual Studio uses for you to define your DataSet, DataTables, and TableAdapters. From it Visual Studio generates normal .cs files: look beneath the .xsd in the Solution Explorer and you can see the classes it produces.

If you right-click on your TableAdapter in your xsd and choose Add > Query then you can enter a new query with parameters, eg SELECT * FROM nef_groups WHERE group_key = @group_key. Visual Studio will automatically create new methods for your TableAdapter to fill or return a dataset with the results of this query, and these methods will take a parameter that gets passed through to the sql query.

Then find your code that currently fills your datatable and replace the Fill method with the new one with a parameter. eg

this.myDataSet.ADataTableAdapter.Fill(this.myDataSet.ADataTable);

would get replaced with something like this:

int myParam = ... (get your parameter value from the query string) ...
this.myDataSet.ADataTableAdapter.MyNewFillMethod(this.myDataSet.ADataTable, myParam);

hope this helps,

- Rory






Re: Visual C# General Passing arguments to a .xsd (Dataset)

DaveCox

Perfect, I knew it'd be something simple but you never know till you've done it.

Thanks a lot!