sql server数据库查询 [英] sql server database query
本文介绍了sql server数据库查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我在sql服务器中运行它时查询到了正确的结果,但是我在代码中输入了结果更改了吗?
这是我的查询
SELECT [dat],[product_id] FROM [market].[dbo].[product]其中dat> =''2012/11/1''和dat< ="2012/11/11''
这是我的代码
Hello,
I''ve query when I run it in the sql server it gives me the correct result ,but I put in my code the result changed?
This is my query
SELECT [dat] ,[product_id]FROM [market].[dbo].[product] where dat>=''2012/11/1'' and dat<=''2012/11/11''
This is my code
SqlConnection con=new SqlConnection (@"Data Source=.\Ahmed;Initial Catalog=Market;Integrated Security=True");
String data = "SELECT [dat] ,[product_id]FROM [market].[dbo].[product] where dat>='2012/11/1' and dat<='2012/11/11'";
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;
推荐答案
只需尝试更改日期以确认格式正确.
Simply try changing the date to verify the formatting is correct.
String data = "SELECT [dat] ,[product_id]FROM [market].[dbo].[product] where dat>=''2012/11/1'' and dat<=''2012/11/30''";
要真正解决它,请将日期格式设置为YYYY-MM-DD:
To really solve it, format the date like YYYY-MM-DD:
String data = "SELECT [dat] ,[product_id]FROM [market].[dbo].[product] where dat>=''2012-11-1'' and dat<=''2012-11-30''";
祝你好运!
Good luck!
这篇关于sql server数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文