在insert 操作过程中报错问题

zzmdegm 2005-05-09 11:03:09
Dim mycon As SqlConnection = New SqlConnection(con)
mycon.Open()
Dim mycom As SqlCommand = New SqlCommand("insert into bookin(customname,customID,roomno,indate,discount,inmemo) values ('" + Trim(Me.T_Dgkname.Text) + "','" + Trim(Me.T_Dgkid.Text) + "','" + Trim(Me.C_Dkfbh.SelectedItem) + "','" + Trim(Me.T_Dtime.Text) + "'," + Trim(Me.T_Dzk.Text) + ",'" + Trim(Me.T_Dbzxx.Text) + "')", mycon)
Dim myupdata As Integer = mycom.ExecuteNonQuery
mycon.Close()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
运行到"Dim myupdata As Integer = mycom.ExecuteNonQuery"行总是报错。
但把
insert into bookin(customname,customID,roomno,indate,discount,inmemo) values ('" + Trim(Me.T_Dgkname.Text) + "','" + Trim(Me.T_Dgkid.Text) + "','" + Trim(Me.C_Dkfbh.SelectedItem) + "','" + Trim(Me.T_Dtime.Text) + "'," + Trim(Me.T_Dzk.Text) + ",'" + Trim(Me.T_Dbzxx.Text) + "')
单独放在sql查询器内运行又很正常,这是为什么啊?
...全文
154 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
pshy 2005-05-10
  • 打赏
  • 举报
回复
你应该没有插入主键吧?自动增值类型的主键不能插入

(数据类型错误)要不就可能是有空格的问题,因为你有数值字段
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
另:这个表的主键是一个自动增长的整型
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
to:smx717616()
Dim myupdata As Integer = mycom.ExecuteNonQuery
------>
mycom.ExecuteNonQuery
这样 改之后还是出错!
机器人 2005-05-10
  • 打赏
  • 举报
回复
如果是Sql Server的话,要加 # 符号表示日期格式。

#yyyy/MM/dd hh:mm:ss#
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
错误提示:

未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。

其他信息: 系统错误。
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
我明白了,是Me.T_Dtime.Text内的值与sql的“datetime”类型不对。

Dim mydt As DateTime = New DateTime().Now
Me.T_Dtime.Text= Format(mydt, "yyyy/MM/dd hh/mm/ss")

这个Format(mydt, "yyyy/MM/dd hh/mm/ss")的格式错在什么地方啊!!
dapang731 2005-05-10
  • 打赏
  • 举报
回复
那就不要再囘傳參數了,要 Dim myupdata As Integer 幹嗎啊 ,把 inert 放在 TRY 裏面,不成功就catch 掉,成功就走FINALY,不就行了
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
to : pshy(无心)
没有啊!主键是bookin啊!

机器人 2005-05-10
  • 打赏
  • 举报
回复
Due to many variables in the format of input data for a date, the date may not always be a string of characters that is recognizes as a date by SQL Server. When you have this kind of raw date data, you will need to manipulate the input data to look like a date, before inserting it into a date/time column. A good example of a date format that is not recognized by SQL Server is an 8 digit date in MMDDYYYY format, this 8 character date format is not recognized by SQL Server as a date. In order to get the MMDDYYYY date into SQL Server you will need to convert it to a format that SQL Server knows is a date, like 'MM-DD-YYYY'. Let's look at ways to convert date/time data into a format that SQL Server can recognize.

如果你那个字段是为了保存系统最新时间的话,可以用SYSDATE--Oracle , GETDATE()--MS SQL
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
自己解决:

方法1:Me.T_Dtime.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")

方法2:Dim mt As DateTime = Now()
Me.T_Dtime.Text = Format(mt, "yyyy-MM-dd hh:mm:ss")
zzmdegm 2005-05-10
  • 打赏
  • 举报
回复
to:fangxinggood(JustACoder)
还是报错啊!
信息:
“Syntax error converting datetime from character string.”
smx717616 2005-05-09
  • 打赏
  • 举报
回复
什么错误?
smx717616 2005-05-09
  • 打赏
  • 举报
回复
如果不出错就是这里的问题。。
smx717616 2005-05-09
  • 打赏
  • 举报
回复
Dim myupdata As Integer = mycom.ExecuteNonQuery
------>
mycom.ExecuteNonQuery

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧