vb.net - 带有“where date ="”的sql语句 [英] vb.net - sql statement with "where date ="

查看:51
本文介绍了vb.net - 带有“where date ="”的sql语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






我在使用sql语句访问ms-access数据库时遇到问题,比如

这个:


SELECT * FROM laTable WHERE laDate =#05/21/2004#;

with asp.net(vb code)


laTable包含一个laDate datetime字段。


请求在ms-access中工作,但不在asp.net中,

我得到内部自动化错误在线:

OleDbDataAdapt.ExecuteReader()


我无法理解...


如果我运行一个带有where的请求除了日期之外的其他东西,

它在访问和asp中都有效。


我尝试过其他一些东西:

with '' => donnees incompatibles dans le critere

with date and time =>自动化错误

与LIKE而不是 = =>自动化错误


从现在开始几天我很忙...


感谢您的帮助


- yannick -


PS:

config:

访问2000数据库/ asp。 net framework 1.1 / VS.net

代码:

requete =" SELECT * FROM laTable WHERE laDate =#05/21/2004#


OleData_prod.SelectCommand.Connection = OLE_dataBase

OleData_prod.SelectCommand.CommandType = CommandType.Text

OleData_prod.SelectCommand.CommandText = requete


OleData_prod.SelectCommand.Connection.Open()


OleData_prod.SelectCommand.ExecuteReader()


OleData_prod.SelectCommand.Connection.Close()


OleData_prod.Fill(leDataset)

解决方案

< blockquote>尝试使用参数代替。


Dim cn As New OleDb.OleDbConnection(" Provider = Microsoft.Jet.OLED B.4.0; Data

源= QUOT; &安培; Server.MapPath(ConfigurationSettings.AppSettings(" dbPath")))

Dim cmd As New OleDbCommand(" SELECT * FROM laTable WHERE laDate = @ laDate",

cn)

cmd.Parameters.Add(New OleDbParameter(" @ laDate",OleDbType.Date))。Value =

New DateTime(2004,5,21)

HTH,

Greg


" Yannick" < PO **** @ nowhere.com>在留言中写道

新闻:MP ************************ @ news.wanadoo.fr ...




我在使用sql语句访问ms-access数据库时遇到了问题,例如:
SELECT * FROM laTable WHERE laDate =#05/21/2004#;
with asp.net(vb code)

laTable包含一个laDate datetime字段。

请求在ms-access中工作,但不在asp.net中,
我得到内部自动化错误在线:
OleDbDataAdapt.ExecuteReader()

我无法理解...

如果我运行带有where的请求除了日期之外的其他东西,
它在访问和asp中都有效。

我尝试过其他一些东西:
with '' => donnees不兼容dans le critere
日期和时间=>自动化错误
使用LIKE而不是 = =>自动化错误

我很忙,因为现在几天......

感谢您的帮助

- yannick -

PS:
config:
访问2000数据库/ asp.net框架1.1 / VS.net

代码:
requete =" ; SELECT * FROM laTable WHERE laDate =#05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand .CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection。关闭()

OleData_prod.Fill(leDataset)



嗯,只是尝试一下,请你检查其他还有吗?

更多内容适用于d / m / y和m / d / y

,因为不使用21,因为它的日期时间你遇到格式错误

遇到..试试#05/05/2004#并看看你是否收到错误...


Yannick < PO **** @ nowhere.com>在留言中写道

新闻:MP ************************ @ news.wanadoo.fr ...




我在使用sql语句访问ms-access数据库时遇到了问题,例如:
SELECT * FROM laTable WHERE laDate =#05/21/2004#;
with asp.net(vb code)

laTable包含一个laDate datetime字段。

请求在ms-access中工作,但不在asp.net中,
我得到内部自动化错误在线:
OleDbDataAdapt.ExecuteReader()

我无法理解...

如果我运行带有where的请求除了日期之外的其他东西,
它在访问和asp中都有效。

我尝试过其他一些东西:
with '' => donnees不兼容dans le critere
日期和时间=>自动化错误
使用LIKE而不是 = =>自动化错误

我很忙,因为现在几天......

感谢您的帮助

- yannick -

PS:
config:
访问2000数据库/ asp.net框架1.1 / VS.net

代码:
requete =" ; SELECT * FROM laTable WHERE laDate =#05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand .CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection。关闭()

OleData_prod.Fill(leDataset)


嗯这只是尝试一下,你有没有检查过其他日期呢?

更多用于d / m / y和m / d / y

的内容,因为不要使用21,因为它是一个日期时间格式错误,你是

遇到..尝试#05/05/2004#并看看你是否收到错误...


Yannick < PO **** @ nowhere.com>在消息中写道

新闻:MP ************************ @ news.wanadoo.fr ...


我在使用sql语句访问ms-access数据库时遇到了问题,如
这个:

SELECT * FROM laTable WHERE laDate = #05/21/2004#;
使用asp.net(vb代码)

laTable包含一个laDate datetime字段。

请求在ms-access中工作,但不在asp.net中,
我得到内部自动化错误在线:
OleDbDataAdapt.ExecuteReader()

我无法理解...

如果我运行带有where的请求除了日期之外的其他东西,
它在访问和asp中都有效。

我尝试过其他一些东西:
with '' => donnees不兼容dans le critere
日期和时间=>自动化错误
使用LIKE而不是 = =>自动化错误

我很忙,因为现在几天......

感谢您的帮助

- yannick -

PS:
config:
访问2000数据库/ asp.net框架1.1 / VS.net

代码:
requete =" ; SELECT * FROM laTable WHERE laDate =#05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand .CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection。关闭()

OleData_prod.Fill(leDataset)






以下是使用northwind数据库的示例。

Private Sub Page_Load(ByVal sender As System.Object,ByVal e As

System.EventArgs)Handles MyBase.Load


''用户代码初始化页面

如果不是Me.IsPostBack那么

BindDataToGrid()

结束如果

结束子


私有子BindDataToGrid()

Dim strConn As String

Dim conn作为OleDb.OleDbConnection

Dim cmdOrders作为OleDb.OleDbCommand

Dim dr As OleDb.OleDbDataReader


strConn =" Provider = Microsoft.Jet.OLEDB.4.0;"

strConn& =" Data Source = C:\Northwind.mdb;"


conn =新OleDb.OleDbConnection(strConn)

cmdOrders =新OleDb.OleDbCommand(" Select OrderID,OrderDate,

来自订单的ShipVia,其中OrderDate =#01/01/1998#",conn)


conn.Open()


dr = cmdOrders.ExecuteReader(CommandBehavior.CloseConnect ction)


DataGrid1.DataSource = dr

DataGrid1.DataBind()

End Sub



---------------------------------


"&的Yannick QUOT; < PO **** @ nowhere.com>在留言中写道

新闻:MP ************************ @ news.wanadoo.fr:



我在使用sql语句访问ms-access数据库时遇到了问题,如
这个:

SELECT * FROM laTable WHERE laDate =#05/21/2004#;
with asp.net(vb code)

laTable包含一个laDate datetime字段。

请求在ms-access中工作,但不在asp.net中,
我得到内部自动化错误在线:
OleDbDataAdapt.ExecuteReader()

我无法理解...

如果我运行带有where的请求除了日期之外的其他东西,
它在访问和asp中都有效。

我尝试过其他一些东西:
with '' => donnees不兼容dans le critere
日期和时间=>自动化错误
使用LIKE而不是 = =>自动化错误

我很忙,因为现在几天......

感谢您的帮助

- yannick -

PS:
config:
访问2000数据库/ asp.net框架1.1 / VS.net

代码:
requete =" ; SELECT * FROM laTable WHERE laDate =#05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand .CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection。关闭()

OleData_prod.Fill(leDataset)




-

外发邮件已通过无病毒认证。

由AVG Anti-Virus检查( http://www.grisoft。 com)

版本:7.0.230 /病毒库:263.3.6 - 发布日期:6/25 / 2004



Hi,

I''ve got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt.ExecuteReader()

I can''t understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I''ve tried some other things:
with " '' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I''m busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand.CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection.Close()

OleData_prod.Fill(leDataset)

解决方案

Try using parameters instead.

Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data
Source=" & Server.MapPath(ConfigurationSettings.AppSettings(" dbPath")))
Dim cmd As New OleDbCommand("SELECT * FROM laTable WHERE laDate = @laDate",
cn)
cmd.Parameters.Add(New OleDbParameter("@laDate", OleDbType.Date)).Value =
New DateTime(2004, 5, 21)
HTH,
Greg

"Yannick" <po****@nowhere.com> wrote in message
news:MP************************@news.wanadoo.fr...


Hi,

I''ve got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt.ExecuteReader()

I can''t understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I''ve tried some other things:
with " '' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I''m busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand.CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection.Close()

OleData_prod.Fill(leDataset)



hmm just something to try, have u checked other dates yet ?
something more in the line that works for d/m/y and m/d/y
as in dont use 21 incase its a datetime format error that you are
encountering.. try #05/05/2004# and see if u get an error...

"Yannick" <po****@nowhere.com> wrote in message
news:MP************************@news.wanadoo.fr...


Hi,

I''ve got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt.ExecuteReader()

I can''t understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I''ve tried some other things:
with " '' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I''m busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand.CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection.Close()

OleData_prod.Fill(leDataset)
hmm just something to try, have u checked other dates yet ?
something more in the line that works for d/m/y and m/d/y
as in dont use 21 incase its a datetime format error that you are
encountering.. try #05/05/2004# and see if u get an error...

"Yannick" <po****@nowhere.com> wrote in message
news:MP************************@news.wanadoo.fr...
Hi,

I''ve got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt.ExecuteReader()

I can''t understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I''ve tried some other things:
with " '' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I''m busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand.CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection.Close()

OleData_prod.Fill(leDataset)



Hi,

Here is sample using the northwind database.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

''Put user code to initialize the page here
If Not Me.IsPostBack Then
BindDataToGrid()
End If
End Sub

Private Sub BindDataToGrid()
Dim strConn As String
Dim conn As OleDb.OleDbConnection
Dim cmdOrders As OleDb.OleDbCommand
Dim dr As OleDb.OleDbDataReader

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"
strConn &= "Data Source = C:\Northwind.mdb;"

conn = New OleDb.OleDbConnection(strConn)

cmdOrders = New OleDb.OleDbCommand("Select OrderID, OrderDate,
ShipVia from Orders where OrderDate = #01/01/1998#", conn)

conn.Open()

dr = cmdOrders.ExecuteReader(CommandBehavior.CloseConne ction)

DataGrid1.DataSource = dr
DataGrid1.DataBind()
End Sub

Ken
---------------------------------

"Yannick" <po****@nowhere.com> wrote in message
news:MP************************@news.wanadoo.fr:

Hi,

I''ve got a problem accessing a ms-access db with a sql statement like
this:

SELECT * FROM laTable WHERE laDate = #05/21/2004# ;
with asp.net (vb code)

laTable contains a "laDate" datetime field .

Request works in ms-access, but not in asp.net,
I get "internal automation error" on line:
OleDbDataAdapt.ExecuteReader()

I can''t understand...

If I run a request with a "where" on something other than a date stuff,
it works both in access and asp.

I''ve tried some other things:
with " '' " => donnees incompatibles dans le critere
with date and time => automation error
with LIKE instead of " = " => automation error

I''m busy with that since now a few days...

thanks for any help

-- yannick --

PS:
config:
access 2000 database / asp.net framework 1.1 / VS.net

code:
requete = "SELECT * FROM laTable WHERE laDate = #05/21/2004#

OleData_prod.SelectCommand.Connection = OLE_dataBase
OleData_prod.SelectCommand.CommandType = CommandType.Text
OleData_prod.SelectCommand.CommandText = requete

OleData_prod.SelectCommand.Connection.Open()

OleData_prod.SelectCommand.ExecuteReader()

OleData_prod.SelectCommand.Connection.Close()

OleData_prod.Fill(leDataset)



--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004


这篇关于vb.net - 带有“where date =&quot;”的sql语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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