本文介绍了水晶报告日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我遇到了水晶报告的正式问题.我从以下网站获取了代码:
http://csharp.net-informations.com/crystal- reports/csharp-crystal-reports-date-to-date.htm [ ^ ]
,但是当我做正式手续时,却给出了错误字符串.

[edit]从以下评论中复制的其他信息:[/edit]
另外,我找到了这段代码并对它进行了一些更改,但是问题是它给了我所有的日期?

Hello,
I''ve crystal report formal problem .I took the code from this website:
http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-date-to-date.htm[^]
,but when I do the formal it gave error string required.

[edit]Additional information copied from comment below:[/edit]
Also, I found this code and did some changes on it ,but the problem is it gives me all the date?

private void button1_Click(object sender, EventArgs e)
        {
            string from_date = textBox1.Text ;
            string to_date = textBox2.Text;
            SqlConnection con=new SqlConnection (@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True");
            String data = "SELECT * from Product  where dat>='"+from_date+"' and dat<='"+to_date+"'";
            con.Open();
            SqlDataAdapter ad1 = new SqlDataAdapter(data, con);
            DataSet ds1 = new DataSet();
            ad1.Fill(ds1);
            ReportDocument cr  = new ReportDocument();
            cr.Load(@"C:\Users\Ahmed\Documents\Visual Studio 2010\Projects\WindowsFormsApplication9\WindowsFormsApplication9\CrystalReport4.rpt");

            cr.SetDataSource(ds1.Tables["product"]);
            crystalReportViewer1.ReportSource = cr;

        }

推荐答案

private void button1_Click(object sender, EventArgs e)
        {
            string from_date = textBox1.Text ;
            string to_date = textBox2.Text;
            DataSet ds1 = new DataSet();
            ReportDocument cr  = new ReportDocument();

            using (SqlConnection con=new SqlConnection (@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True")){
                String data = "SELECT * from Product  where dat BETWEEN @StartDate AND @EndDate";
                con.Open();
                using (SqlCommand cmd = new SqlCommand(data, conn))
                {
                    // you are going to need to parse these dates in their expected format
                    // Convert.ToDateTime has some overrides for that
                    // See below for some links for some reading
                    cmd.Parameters.Add(new SqlParameter("@StartDate", Convert.ToDateTime(from_date));
                   cmd.Parameters.Add(new SqlParameter("@EndDate", Convert.ToDateTime(to_date));
                   using (SqlDataAdapter ad1 = new SqlDataAdapter(cmd))
                   {
                      ad1.Fill(ds1);
                   }
                }
            }

            cr.Load(@"C:\Users\Ahmed\Documents\Visual Studio 2010\Projects\WindowsFormsApplication9\WindowsFormsApplication9\CrystalReport4.rpt");

            cr.SetDataSource(ds1.Tables["product"]);
            crystalReportViewer1.ReportSource = cr;

        }



您可能应该阅读这些内容,所以这里有一些链接:
运算符之间的SQL [ ^ ]
SqlCommand类 [ ^ ]
SqlParameter类 [ ^ ]
使用语句的C# [ ^ ]
DateTime.TryParseExact [ ^ ]
Convert.ToDateTime [ ^ ]



You should probably read up on this stuff so here are some links:
SQL Between Operator[^]
SqlCommand Class[^]
SqlParameter Class[^]
C# using Statement[^]
DateTime.TryParseExact[^]
Convert.ToDateTime[^]


这篇关于水晶报告日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 12:59