Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamic SQL statement in webform with datagrid
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Divers
Thread ID:
00671307
Message ID:
00671314
Vues:
15
This message has been marked as the solution to the initial question of the thread.
First of all you I would recommend using the SQLDataAdapter and SQLConnection classes instead of the OLEDB. You will get better performance by using the one specifically written for SQL Server.

To update your DataAdapter, what you need to do is in the design window, right-click on the DataAdapter and choose Configure Data Adapter. You will run through the wizard like you did originally. This time when you get to typing in your select statement, you will add the parameters to the existing select statement. For SQL Server, you append an @ before the parameter's name. For example:

select * from customers where customerid like '@ID'

Continue going through the rest of the wizard. When completed, the new code will be created and modified in your project. All the generated code is available to you to look at. The code for the Connection and DataAdapter is in the code-behind of you web page. The code is hidden in a section which you can expand.

Then right before you fill the dataset, you need to set the parameter(s) of the DataAdapter to the correct values, like:

SqlDataAdapter1.SelectCommand.Parameters("@id").Value = "A%"

When the DataSet is filled, the values stored in the parameters collection will be used in the select statement.


>I have a webform running that has a calendar control and a datagrid. I used the data toolbox to drop an oledbDataAdapter on the form (because the book told me too). I then used the Data menu option to generate a dataset (ScheduledCases1), which I built the basic sql query (SQL 2000 for the database). I have the code all working with the data grid getting populated. But I now I need to make a dynamic where clause based on the date they pick in the calendar. So I have to public variables (cStartDate and cEndDate) that stores the date when they click on the calendar. But I don't know how create the dynamic portion of the query. Once I created the dataset with the generate dataset option, is that locked now?
>
>Thanks for any help.
>
>Kirk
>
>I'm using vb.net
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform