首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

往access数据库里插入行的有关问题

2012-03-09 
往access数据库里插入行的问题Dim objConnAs New ADODB.ConnectionDim objRstAs New ADODB.RecordsetDim s

往access数据库里插入行的问题
Dim objConn As New ADODB.Connection
  Dim objRst As New ADODB.Recordset
  Dim sSql As String
  Dim sConn As String
  Dim sEno As Long
  Dim sDay As Date
  Dim sStart As String
  Dim sEnd As String
  sEno = 2
  sDay = Now
  sStart = Trim(Text1.Text)
  sEnd = Trim(Text2.Text)
  sConn = "Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;DATA SOURCE=C:\Documents and Settings\Admin\My Documents\Database1.accdb"
   
  objConn.Open sConn
  sSql = "insert into [Hour] (Day,Eno,Start,End,Interval) values(#" & Format(sDay, "yyyy-mm-dd") & "#, " & sEno & " , #" & Format(sStart, "hh:mm:ss") & "#,#" & Format(sEnd, "hh:mm:ss") & "#," & c & " ) "
  objConn.Execute sSql
   
  objRst.Close
  Set objRst = Nothing
  objConn.Close
  Set objConn = Nothing

想往数据库里添加一行,但是老提示insert into语句有语法错误,access里的hour表里 Day,start,end都是时间日期型,Eno跟Interval是长整形。c也是长整形。高人请帮忙看看

[解决办法]

VB code
'day,start,end等是系统关键字,最好不要用作表名与字段名,一定要用则需要用方括号sSql = "insert into [Hour] ([Day],Eno,[Start],[End],Interval) values(#" & Format(sDay, "yyyy-mm-dd") & "#, " & sEno & " , #" & Format(sStart, "hh:mm:ss") & "#,#" & Format(sEnd, "hh:mm:ss") & "#," & c & " ) "  objConn.Execute sSql 

热点排行