将日期时间值插入sql [英] inserting a datetime value into sql
问题描述
i我正在尝试执行一个语句,其中我将带有datetime
值的记录插入到sql数据库中。
Dim sqlcmd作为新的SqlCommand
sqlcmd.CommandText =" update tbl_event set last_run =''" &
nowTime& "'',event_action = 1,event_time =''" &安培; nextPollTime& "'''
event_id =" &安培; IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
命令文件等于
event_time =''15/07/2008 13:07:42''where event_id = 1
我收到以下错误....
将char数据类型转换为日期时间数据类型导致
out-of - 日期时间值。
我正在做什么错了????
感谢您的帮助
新手,
以下更新声明是否有效:
update tbl_event set last_run =''07/15/2008 13:07:27'',event_action = 1,
event_time =''07/15/2008 13:07:42'' event_id = 1
如果此语句有效,那么问题在于日期时间格式。
Kerry Moorman
" Newbie"写道:
你好...
i我试图执行一个语句,其中我插入日期时间的记录
值到sql数据库中。
Dim sqlcmd作为新的SqlCommand
sqlcmd.CommandText =" update tbl_event set last_run =''' &
nowTime& "'',event_action = 1,event_time =''" &安培; nextPollTime& "'''
event_id =" &安培; IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
命令文件等于
event_time =''15/07/2008 13:07:42''where event_id = 1
我收到以下错误....
将char数据类型转换为日期时间数据类型导致
out-of - 日期时间值。
我正在做什么错了????
感谢您的帮助
是的,它确实...谢谢
它是服务器上的本地化问题还是在客户端....
有没有办法对日期进行编码,以便本地化不成问题?
谢谢
" Kerry Moorman" < Ke ********** @ discussion.microsoft.com写信息
新闻:9F ****************** **************** @ microsof t.com ...
新手,
以下更新声明是否有效:
update tbl_event set last_run =''07/15/2008 13:07:27'',event_action = 1,>
event_time =''07/15/2008 13:07:42''where event_id = 1
如果此语句有效,那么问题在于日期时间格式。
Kerry Moorman
" Newbie"写道:
>你好...
我正在尝试执行一个声明,其中我插入日期时间的记录
值为sql数据库。
Dim sqlcmd为新的SqlCommand
sqlcmd.CommandText =" update tbl_event set last_run =''" &
nowTime& "'',event_action = 1,event_time =''" &安培; nextPollTime& "''where
event_id =" &安培; IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
命令文本等于
更新tbl_event设置last_run ='''年'月/月经期'13:07:27'',event_action = 1,
event_time =''15/07 / 2008 13:07:42''where event_id = 1
我收到以下错误....
将char数据类型转换为datetime数据类型导致了超出范围的日期时间值。
我正在做什么错了????
感谢您的帮助
是和是!
Dim sqlcmd =新的SqlCommand(" update tbl_event set
last_run = @ last_run,event_action = 1,event_time = @ even t_time where
event_id = @ event_id",dbConnectionIn)
sqlcmd.Parameters.Add(" @ last_run",S qlDbType.DateTime).Value = nowTime
sqlcmd.Parameters.Add(" @ event_time",SqlDbType.DateTime).Value =
nextPollTime
sqlcmd.Parameters.Add(" @ event_id",SqlDbType.IntValue = IntEventID
sqlcmd.ExecuteNonQuery()
新手 < ne **** @ spam.comwrote in message
news:eS ************** @ TK2MSFTNGP06.phx.gbl ...
是的,它确实...谢谢
它将成为服务器或客户端上的本地化问题。 ...
有没有办法对日期进行编码,以便本地化不成问题?
谢谢
" Kerry Moorman" < Ke ********** @ discussion.microsoft.com写信息
新闻:9F ****************** **************** @ microsof t.com ...
>新手,
更新tbl_event set last_run =''07/15/2008 13:07:27'',event_action = 1,
event_time =''07 / 15/2008 13:07:42''event_id = 1
如果这个陈述有效,则问题在于日期时间格式。
Kerry Moorman
新手写道:
>>你好...
我正在尝试执行一个语句,其中我插入日期时间
将值转换为sql数据库。
Dim sqlcmd作为新的SqlCommand
sqlcmd.CommandText =" update tbl_event set last_run =''" &
nowTime& "'',event_action = 1,event_time =''" &安培; nextPollTime& "''where
event_id =" &安培; IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
命令文本等于
更新tbl_event设置last_run ='''年'月/月经期'13:07:27'',event_action = 1,
event_time =''15/07 / 2008 13:07:42''where event_id = 1
我收到以下错误....
将char数据类型转换为datetime数据类型导致
超出范围的日期时间值。
我正在做的事情出了什么问题????
感谢您的帮助
howdy...
i am trying to execute a statement where i insert a record with datetime
values into a sql database.
Dim sqlcmd As New SqlCommand
sqlcmd.CommandText = "update tbl_event set last_run = ''" &
nowTime & "'', event_action =1, event_time = ''" & nextPollTime & "'' where
event_id = " & IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
the commandtext equals
update tbl_event set last_run = ''15/07/2008 13:07:27'', event_action =1,
event_time = ''15/07/2008 13:07:42'' where event_id = 1
I get the following error....
The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
Whats wrong with what I am doing ????
Thanks for your help
Newbie,
Does the following update statement work:
update tbl_event set last_run = ''07/15/2008 13:07:27'', event_action =1,
event_time = ''07/15/2008 13:07:42'' where event_id = 1
If this statement works then the problem is with the datetime format.
Kerry Moorman
"Newbie" wrote:
howdy...
i am trying to execute a statement where i insert a record with datetime
values into a sql database.
Dim sqlcmd As New SqlCommand
sqlcmd.CommandText = "update tbl_event set last_run = ''" &
nowTime & "'', event_action =1, event_time = ''" & nextPollTime & "'' where
event_id = " & IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
the commandtext equals
update tbl_event set last_run = ''15/07/2008 13:07:27'', event_action =1,
event_time = ''15/07/2008 13:07:42'' where event_id = 1
I get the following error....
The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
Whats wrong with what I am doing ????
Thanks for your help
Hi, Yes it did...thanks
is it going to be a localisation issue on the server or on the client....
is there a way to code the date so that localisation is not an issue ?
Thanks
"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...Newbie,
Does the following update statement work:
update tbl_event set last_run = ''07/15/2008 13:07:27'', event_action =1,
event_time = ''07/15/2008 13:07:42'' where event_id = 1
If this statement works then the problem is with the datetime format.
Kerry Moorman
"Newbie" wrote:
>howdy...
i am trying to execute a statement where i insert a record with datetime
values into a sql database.
Dim sqlcmd As New SqlCommand
sqlcmd.CommandText = "update tbl_event set last_run = ''" &
nowTime & "'', event_action =1, event_time = ''" & nextPollTime & "'' where
event_id = " & IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
the commandtext equals
update tbl_event set last_run = ''15/07/2008 13:07:27'', event_action =1,
event_time = ''15/07/2008 13:07:42'' where event_id = 1
I get the following error....
The conversion of a char data type to a datetime data type resulted in an
out-of-range datetime value.
Whats wrong with what I am doing ????
Thanks for your help
Yes and Yes!
Dim sqlcmd = New SqlCommand("update tbl_event set
last_run=@last_run,event_action=1,event_time=@even t_time where
event_id=@event_id", dbConnectionIn)
sqlcmd.Parameters.Add("@last_run", SqlDbType.DateTime).Value = nowTime
sqlcmd.Parameters.Add("@event_time", SqlDbType.DateTime).Value =
nextPollTime
sqlcmd.Parameters.Add("@event_id", SqlDbType.IntValue = IntEventID
sqlcmd.ExecuteNonQuery()
"Newbie" <ne****@spam.comwrote in message
news:eS**************@TK2MSFTNGP06.phx.gbl...Hi, Yes it did...thanks
is it going to be a localisation issue on the server or on the client....
is there a way to code the date so that localisation is not an issue ?
Thanks
"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:9F**********************************@microsof t.com...>Newbie,
Does the following update statement work:
update tbl_event set last_run = ''07/15/2008 13:07:27'', event_action =1,
event_time = ''07/15/2008 13:07:42'' where event_id = 1
If this statement works then the problem is with the datetime format.
Kerry Moorman
"Newbie" wrote:
>>howdy...
i am trying to execute a statement where i insert a record with datetime
values into a sql database.
Dim sqlcmd As New SqlCommand
sqlcmd.CommandText = "update tbl_event set last_run = ''" &
nowTime & "'', event_action =1, event_time = ''" & nextPollTime & "'' where
event_id = " & IntEventID
Debug.Print(sqlcmd.CommandText)
sqlcmd.Connection = dbConnectionIn
sqlcmd.CommandType = CommandType.Text
sqlcmd.ExecuteNonQuery()
the commandtext equals
update tbl_event set last_run = ''15/07/2008 13:07:27'', event_action =1,
event_time = ''15/07/2008 13:07:42'' where event_id = 1
I get the following error....
The conversion of a char data type to a datetime data type resulted in
an
out-of-range datetime value.
Whats wrong with what I am doing ????
Thanks for your help
这篇关于将日期时间值插入sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!