没有结果报告 [英] having no result in report
本文介绍了没有结果报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用此代码显示搜索crystalreportviewer的结果.
它过滤两个日期和两个id之间的数据.
当我执行它时,它不会显示任何结果.
此代码有什么问题?????
i use this code to show the results of searching into crystalreportviewer.
it filters data between two date and two id .
when i execute it, it doesnt show any result.
what''s wrong in this code?????
private void btnSearch_Click(object sender, EventArgs e)
{
SqlDataAdapter adapt = new SqlDataAdapter();
adapt.SelectCommand = new SqlCommand();
adapt.SelectCommand.Connection = cnn;
adapt.SelectCommand.CommandType = CommandType.Text;
adapt.SelectCommand.CommandText = "SELECT * FROM View_Selling WHERE (khdate >=''" + txtFromDate.Text.Trim() + "'' AND khdate < ''" + txtToDate.Text.Trim() + "'') AND (id >=''" + txtFromCode.Text.Trim() + "'' AND id < ''" + txtToCode.Text.Trim() + "'') ";
DataSet dset = new DataSet();
cnn.Open();
adapt.Fill(dset, "View_Selling");
cnn.Close();
CrystalReport1 objRPT = new CrystalReport1();
objRPT.SetDataSource(dset);
crystalReportViewer1.ReportSource = objRPT;
}
帮帮我
非常感谢
[edit]已添加代码块-OriginalGriff [/edit]
help me
thanks alot
[edit]Code block added - OriginalGriff[/edit]
推荐答案
您实际上是在ID上进行比较.
在这种情况下,您可能需要使用数字类型而不是字符串类型.
删除查询<=''" + txtFromCode.Text.Trim() + "'' AND
中的引号可能应该是<=" + txtFromCode.Text.Trim() + " AND
.
You are actually doing a compare on the id.
In that case, you will need to probably use numeric types rather than string types.
Remove the quotes in the query<=''" + txtFromCode.Text.Trim() + "'' AND
should probably be<=" + txtFromCode.Text.Trim() + " AND
.
要添加Abhinav所说的内容,根本不要那样做.串联字符串是一个非常糟糕的主意-如果用户意外地破坏数据库,它可能导致SQL Injection攻击.请改用参数化查询:
To add to what Abhinav says, don''t do it that way at all. Concatenating strings is a very bad idea - it can lead to SQL Injection attacks, were a user can accidentally of deliberately destroy your database. Use parametrised queries instead:
adapt.SelectCommand = new SqlCommand();
adapt.SelectCommand.Connection = cnn;
adapt.SelectCommand.CommandType = CommandType.Text;
adapt.SelectCommand.CommandText = "SELECT * FROM View_Selling WHERE (khdate >=@FRDATE AND khdate < @TODATE) AND (id >=@FRID AND id < @TOID)";
adapt.SelectCommand.Parameters.AddWithValue("@FRDATE", DateTime.Parse(txtFromDate.Text.Trim()));
adapt.SelectCommand.Parameters.AddWithValue("@TODATE", DateTime.Parse(txtToDate.Text.Trim()));
...
无论如何,这可能会解决您的问题,因为无论如何,用户不太可能以正确的格式(即"yyyy-MM-dd")输入SQL Server的日期.
This will probably get rid of your problem anyway, since the user is unlikely to be entering the dates in the correct (i.e. "yyyy-MM-dd") format for SQL server anyway.
这篇关于没有结果报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文