Solved

Dynamic STRONGLY Typed Dataset Queries

Posted on 2009-05-20
6
729 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

690 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