Solved

Dynamic STRONGLY Typed Dataset Queries

Posted on 2009-05-20
6
725 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

732 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