Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
When I want to search for a student record indexed using the student ID I will get that student ID from a text box in a vb 2005 form.

So how can I pass that value for the SQL WHERE clause in the crystal report?
Posted
Comments
Tarun Mangukiya 28-Jun-11 3:48am    
Please describe

You can do this using the below code;
Dim cnn As SqlConnection
Dim connectionString As String
Dim sql As String

connectionString = "data source=[servername];initial catalog=[databasename];user id=[username];password=[password];"
cnn = New SqlConnection(connectionString)
cnn.Open()
Dim sqlString as String
sqlString = "Select * From Table1 Where ID = " & txtID.Text
Dim dscmd As New SqlDataAdapter(sqlString, cnn)
Dim ds As New DataSet1
dscmd.Fill(ds, "Table1")
objRpt.SetDataSource(ds.Tables(1))
CrystalReportViewer1.ReportSource = objRpt
CrystalReportViewer1.Refresh() 

Hope this helps... :)

Jasmin
 
Share this answer
 
v2
Comments
rose lindo 1-Sep-12 7:14am    
thanks it working
Solution provided by jasmin is also true, but only in case you are passing data from application,

but if you are using tables in report, then there is a selectionformula property of Crystal Report viewer.

put your where clause in this property in the below format :

{tablename.fieldname}>2, something like this.

Hope that helps.
 
Share this answer
 
guys thank you for the solutions above. after numerous attempts i was getting frustrated as i could prepare my crystal reports but if i had to filter to just one specific record i was suffering. old article but worth the read! thank you :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900