在两个日期之间获得错误 [英] Getting error between two dates

查看:79
本文介绍了在两个日期之间获得错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Guys,我面临类似的问题,我不知道为什么我得到这个错误实际问题是我想从两个日期之间的db获取数据

错误是

Hello Guys,i am facing a similar problem i don't know why i am getting this error actually problem is i want to get data from db between two dates
the error is

Additional information: Syntax error in date in query expression '[Dates] between #19:11:2016 11:08:51:PM# AND #19:11:2016 11:08:51:PM'.



请大家给我这个问题的最佳解决方案



Thanksalot



我尝试过:




please guys give me the best solution of this problem

Thanksalot

What I have tried:

DataSet dsa = new DataSet();
            DataTable dt = new DataTable();
            dsa.Tables.Add(dt);
            OleDbDataAdapter da = new OleDbDataAdapter();
            da = new OleDbDataAdapter("SELECT [Items Name],[Quantity],[Price],[Dates] from [Inventory Control] WHERE [Dates] between #" + dateTimePicker1.Text +"# AND #" + dateTimePicker2.Text + "#", connection);
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            connection.Close();
            dataGridView1.Columns[0].Width = 150;
            dataGridView1.Columns[1].Width = 350;
            dataGridView1.Columns[2].Width = 200;
            dataGridView1.Columns[3].Width = 150;

推荐答案

不要这样做!永远不要连接字符串以转向SQL命令 - 它会使您的代码面临SQL注入攻击的风险,这可能会破坏或破坏您的数据库。总是使用参数化查询。



同时,您当前的问题将作为副作用消失...
Don't do it like that! Never concatenate strings to turn at SQL command - it puts your code at risk of SQL Injection attacks, which can damage or destroy your database. Always use parameterized queries instead.

At the same time, your current problem will disappear as a side effect...


这篇关于在两个日期之间获得错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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