Solved

Dynamic STRONGLY Typed Dataset Queries

Posted on 2009-05-20
6
720 Views
Last Modified: 2013-11-26
How do I run a query like this:

Dim dbC As New SqlCommand("SELECT Stat" & Stat.SurvNo & " FROM eV67Survey WHERE uid = " & uid, conn0)
conn0.Open() : ThisResp = dbC.ExecuteScalar() : conn0.Close()

Using Strongly Typed Datasets?

(Is it even possible?)
0
Comment
Question by:Espavo
  • 3
  • 3
6 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24441200
1) I don't know if it it possible.

2) I don't understand why you would want to do that?

3) You can easily run that kind of query outside of the typed DataSet, so it is starting to sound like trying to fit a square peg in a round hole (which you can do with a really big hammer!!).
0
 
LVL 10

Author Comment

by:Espavo
ID: 24441511
2) The reason I would want to do it is 'cause my code using datasets is so much cleaner and more efficient than when using SqlCommands...
3) I'm aware of that... and that's why I was wondering if there may be a different way to do it...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24446352
Do you want to use the QueryAdapter, and extend the typed DataSet class to use dynamic queries?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 10

Author Comment

by:Espavo
ID: 24448021
Seems like I'm barking up a tree... (not sure what a QueryAdaptor is...)
What I'd like to be able to do is replace this:
for i = 1 to 200
Dim dbC As New SqlCommand("SELECT Stat" & i & " FROM eV67Survey WHERE uid = " & uid, conn0)
conn0.Open() : ThisResp = dbC.ExecuteScalar() : conn0.Close()
next
With something like this:
Dim SurvAdaptor As New SQLDataSetTableAdapters.SurveyTableAdapter
for i = 1 to 200
ThisResp = SurvAdaptor.GetStatValue("Stat" & Stat.SurvNo,uid)
next
The DataSet would need to look something like:
SELECT @StatNo FROM eV67Survey WHERE uid = @uid

Thanks, Gayo
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 24450356
Here is a great article from Scott Guthrie, that talks about typed DataSets.

Building a DAL using Strongly Typed TableAdapters and DataTables in VS 2005 and ASP.NET 2.0
http://weblogs.asp.net/scottgu/archive/2006/01/15/435498.aspx

If you use the <Add Query> option from the designer, and create a query, then the designer generates a QueryTableAdapter that you can use to execute queries.
0
 
LVL 10

Author Closing Comment

by:Espavo
ID: 31583689
Thanks... the link above has given me a lot to think about (most of it I know and use already...) I'll follow some of the links from there and see if I have any other luck... (Doesn't look like I'll be getting lucky soon though...)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question