Solved

Dynamic STRONGLY Typed Dataset Queries

Posted on 2009-05-20
6
714 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now