473,516 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating SQL on the fly?

Howdy:

I am an experienced VB 6.0 database programmer trying to write first VS 2005
application in VB 2005. I want to create an end user defined query and pass
it to the program. Specifically, I want to pass a date range, ie:

SELECT * FROM MYDATES WHERE ((theDate) Between #8/1/2006# And #8/7/2006#);

However, the user wants to enter the date range on his own. In the past I
would generate the SQL on the fly and pass it to a datacontrol as the
datasource. Now it seems Queries are made with the Query Builder and stored
in "WhateverDataSet.xsd" file.

How do I retrieve the current "Text" that defineds the query at runtime,
change it, and refresh it to display a new date range?

Eventually, I want to pass this same range to a report. Is that possible?

Thanks,
Ross

Sep 12 '06 #1
7 1176
easiest way to do this is make a command object like this

dim dbConnection as SqlClient.SqlConnect(connString)
using cmd as SqlClient.SqlCommand("SELECT * FROM MYDATES WHERE ((theDate)
BETWEEN @Start AND @End)",dbConnection)

cmd.CommandType = StoredProcedure
' this writes out the sql query text if needed
debug.writeline(cmd.CommandText)
cmd.paramaters.addwithvalue("@Start",#8/1/2006#)
cmd.paramaters.addwithvalue("@End",#9/1/2006#)

using dt as new datatable("MyItems")
dt.Load(cmd.executereader)
for each dr as datarow in dt.rows
debug.writeline(dr("columnname").tostring)
next
end using
end using

this will take the dates in as paramaters, execute them on the given
connection and load the results into a data table, then print them out one
at a time for the given column
Sep 12 '06 #2

Sep 12 '06 #3
I tried this - but this is how you store a specific query into the program. In this way the end user cannot change the query on the fly - or am I not understanding.

Thanks,
Ross
"Robert Porter" <ro**********@nospam.rp2c.comwrote in message news:eI**************@TK2MSFTNGP06.phx.gbl...
A better solution would be to parameterize the query that builds the DataSet, you can either right-click the existing Dataset and then select Add Query or select Configure to modify the existing query.

--

Cheers,



Robert Porter





Sep 12 '06 #4
Hey Smokey:

Thanks for the reply, but when I tried this SqlClient has not SqlConnect
parameter. I tried SqlConnection but this will not take a connection string
parameter. Sorry to be such a newbie.
"Smokey Grindel" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
easiest way to do this is make a command object like this

dim dbConnection as SqlClient.SqlConnect(connString)
using cmd as SqlClient.SqlCommand("SELECT * FROM MYDATES WHERE ((theDate)
BETWEEN @Start AND @End)",dbConnection)

cmd.CommandType = StoredProcedure
' this writes out the sql query text if needed
debug.writeline(cmd.CommandText)
cmd.paramaters.addwithvalue("@Start",#8/1/2006#)
cmd.paramaters.addwithvalue("@End",#9/1/2006#)

using dt as new datatable("MyItems")
dt.Load(cmd.executereader)
for each dr as datarow in dt.rows
debug.writeline(dr("columnname").tostring)
next
end using
end using

this will take the dates in as paramaters, execute them on the given
connection and load the results into a data table, then print them out one
at a time for the given column

Sep 12 '06 #5

Sep 12 '06 #6
Try using ".FilterExpression" and see if it will work for you.

ado2.net is much more complicated than the ado we were using. Some vb6
programmers think it is hard to learn the vb.net language. I have found
that it is easy compared to ado2.net. Why they even call it ado any longer
is strange. ado2.net is for web programmers who use disconnected data.


"Ross Contino" <ro*********@comcast.netwrote in message
news:fY******************************@suscom.com.. .
Howdy:

I am an experienced VB 6.0 database programmer trying to write first VS
2005
application in VB 2005. I want to create an end user defined query and
pass
it to the program. Specifically, I want to pass a date range, ie:

SELECT * FROM MYDATES WHERE ((theDate) Between #8/1/2006# And #8/7/2006#);

However, the user wants to enter the date range on his own. In the past I
would generate the SQL on the fly and pass it to a datacontrol as the
datasource. Now it seems Queries are made with the Query Builder and
stored
in "WhateverDataSet.xsd" file.

How do I retrieve the current "Text" that defineds the query at runtime,
change it, and refresh it to display a new date range?

Eventually, I want to pass this same range to a report. Is that possible?

Thanks,
Ross

Sep 13 '06 #7
Do you have to have MS Sql Server installed to use these commands? The
machine I am programming on is also set to develop PHP/MySQL and is running
Apache. Hence, I did not install MS Sql Server when installing VS 2005.
The following is not available to me while programming:

using cmd as SqlClient.SqlCommand("SELECT * FROM MYDATES WHERE ((theDate)
BETWEEN @Start AND @End)",dbConnection)

SqlCommand is an invalid property and when I search MSDN it is referenced to
SQL Server.

I think I am just a newbie - but cannot imagine that there is not a simple
equivalent to the way we used to just pass a SQL statement to a Data Control
and refresh!! I was always able to create end user generated queries on the
fly. (Enough wining)

Thanks,
Ross

"phonl" <ph***@newsgroups.nospamwrote in message
news:eF**************@TK2MSFTNGP05.phx.gbl...
Try using ".FilterExpression" and see if it will work for you.

ado2.net is much more complicated than the ado we were using. Some vb6
programmers think it is hard to learn the vb.net language. I have found
that it is easy compared to ado2.net. Why they even call it ado any
longer is strange. ado2.net is for web programmers who use disconnected
data.


"Ross Contino" <ro*********@comcast.netwrote in message
news:fY******************************@suscom.com.. .
>Howdy:

I am an experienced VB 6.0 database programmer trying to write first VS
2005
application in VB 2005. I want to create an end user defined query and
pass
it to the program. Specifically, I want to pass a date range, ie:

SELECT * FROM MYDATES WHERE ((theDate) Between #8/1/2006# And
#8/7/2006#);

However, the user wants to enter the date range on his own. In the past
I
would generate the SQL on the fly and pass it to a datacontrol as the
datasource. Now it seems Queries are made with the Query Builder and
stored
in "WhateverDataSet.xsd" file.

How do I retrieve the current "Text" that defineds the query at runtime,
change it, and refresh it to display a new date range?

Eventually, I want to pass this same range to a report. Is that
possible?

Thanks,
Ross


Sep 13 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2019
by: paul | last post by:
Hi, I'd like to generate PDF files from my Php website. I've found PDFLib to make it... but i'd like to have your views. It is the best I can find ? Are there any other PDF generating lib ? Is there a totally free PDF generating lib ? Thanks in advance,
0
1893
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing build release comparisons (I use a script to generate a main page showing all the files that were changed in a build with hyperlinks to side by side...
0
1779
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n numbers. def combo2(n): return dict() print combo2(5)
17
2115
by: flupke | last post by:
Hi, i create my GUIs mainly via wxGlade. However when you start of to program and want to do some rearranging to the gui, wxglade overwrites your file and you've got to put your own code back in. I think i can work around that (at least a bit) by making a second file that imports the gui generated by wxglade and make classes that extend...
3
10554
by: skn | last post by:
Hello., Does the python compiler provide an option to generate a .pyo(optimized byte code file) from a .py (source file)? For generating .pyc I know that I only have to pass the source file name as an argument to py_compile.py. But for generating .pyo, I could not find anything. Any clues/help will be greatly appreciated.
3
9423
by: Raed Sawalha | last post by:
Hello when I serialize an object an error generated using this function public string SerializeObject(object oClassObject,System.Type oClassType) { XmlSerializer oSerializer = new XmlSerializer(oClassType); System.Text.StringBuilder strBuilder = new System.Text.StringBuilder(); System.IO.TextWriter writer = new...
1
2182
by: Nathan Sokalski | last post by:
Visual Studio 2005 recently stopped generating the *.designer.vb files for my *.aspx and *.ascx files. I am using Service Pack 1, and do not believe I did anything differently than normal prior to this happening. Is there anything that could have caused this? Does anyone know of a way to fix it? Thanks. -- Nathan Sokalski...
3
8796
by: deciacco | last post by:
I'm trying to write a label printing SDI app with a small preview on the main form itself. Every time I run the InvalidatePreview event on the preview control to redraw the preview I get the "Generating Previews" dialog box while the preview is being generated. I want to suppress this. I've been able to find this from another forum: "The...
0
1833
by: Aswanth | last post by:
I'm Generating Reports in SSRS-2005.. Previously I got the Data from One Database & Generated Reports.. Now I used to get the Data from Two Different Databases(ie Database-1 & Database-2) & to generate the Reports.. I'm having one Stored Procedure(Get_Data) which will combine Two databases & get the data from them.. It is working fine for...
0
1874
by: Aswanth | last post by:
I'm Working with Asp.Net with C#.. & I'm Generating Reports in SSRS-2005.. Till Now I'm Generating Reports in SSRS-2005 with Stored Procedure.. in Which I'm Generating Reports for One Particular User Details(ie I wrote Stored Procedure for Getting One Users Details).. Now I Want to Generate the Reports for Different...
0
7276
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7581
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7142
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7548
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4773
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3267
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1624
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
825
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.