Question Locked

Parsing query from VB Application to Data Report

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hii,
I want to send the sql statement from vb application to the datareport, and wants to call the data report. Please help me out with example code to change the sql statement already made with the data report through VB application.

Thanks and Regards.

3 replies

by fazeel.amjad

HI

I am Fazeel Amjad experienced in designing data driven application with Visual Basic and SQL Server 2000/2005.

I am writing here an example for you.

It is assumed that you have a table named Products with these fields
ProductID, ProductName, QtyInStock, SalePrice

it is also assumed that you have setup a datareport with above named fields to display reports. never forget to the set the Datafield value of fields in detail section of the datareport. the datafield value will be the fields in query i.e. productid, productname etc.

Private Function PrintProductsInStock()
Dim SQL as String
Dim Conn as ADODB.Connection
Dim Rs as New ADODB.Recordset

' you must setup Conn parameters to connect to the db. i.e. connection string

If Conn.State = adStateClosed Then Conn.Open

SQL="SELECT ProductID, ProductName, QtyInStock, SalePrice From Products Where QtyInStock>0"

SET Rs=Conn.Execute(SQL)

If Rs.EOF<>True then
rptProducts.Datasource=Rs
else
msgbox "No record found.",vbCritical
exit function
End If

rptProducts.Refresh
rptProducts.Show

End Function

Hope this will solve your problem.

If you need my further help here is my contact info.

Fazeel Amjad
CEO
(Artis Interactive)
Pakistan

Mob: 0092-333-7439717
email: fazeel.amjad@gmail.com

by yvesval

I would like to ask for a favor regarding my simple program requirements. Is it possible to create an sql query that would display by date range. example of that is;

Viewing of report of all male or female that are registered from 1/1/2011 to 2/28/2011. there are two TEXTBOX or COMBOBOX and a Button VIEW REPORT in the form.

Hope to hear from you.

This discussion is closed to new replies.