如何在VB 2005文本框的水晶报表中获取SQL WHERE子句的值? [英] How can I get a value for the SQL WHERE Clause in a crystal report from a VB 2005 textbox?

查看:54
本文介绍了如何在VB 2005文本框的水晶报表中获取SQL WHERE子句的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想搜索使用学生ID索引的学生记录时,我将从vb 2005表单的文本框中获取该学生ID。



所以如何在Crystal报表中传递SQL WHERE子句的值?

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?

推荐答案

您可以使用以下代码执行此操作;

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() 



希望这有助于...... :)



Jasmin


Hope this helps... :)

Jasmin


jasmin提供的解决方案也是如此,但仅在您从应用程序传递数据的情况下,



但是如果你在报表中使用表格,那么Crystal Report查看器就有一个selectionformula属性。



把你的where子句放入这个属性的格式如下:



{tablename.fieldname}> 2,就像这样。



希望有所帮助。
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.


伙计们感谢您提供上述解决方案。经过多次尝试后,我感到沮丧,因为我可以准备我的水晶报告,但如果我必须过滤到一个特定的记录,我正在遭受痛苦。旧文章,但值得一读!谢谢:)
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 :)


这篇关于如何在VB 2005文本框的水晶报表中获取SQL WHERE子句的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆