# Re: 下列SQL那里错误

Posted by Stone on August 13, 1998 at 15:27:58:

In Reply to: 下列SQL那里错误 posted by tsaitang on August 13, 1998 at 09:05:22:

: Type EmployeeRecord
: ID As String * 6
: Name As String * 9
: End Type

上面宣告需在module中

: Dim dbs As Database
: Dim strSQL As String
: dim emp as EmployeeRecord
: Set dbs = DBEngine.Workspaces(0).OpenDatabas("c\maintain\service.mdb")

你的OpenDatabas(e)少了一个e, 磁碟c(:)少了一个:
set dbs=DBEngine.Workspaces(0).OpenDatabase("C:\maintain\service.mdg")

: emp.id=22131
: emp.name=tang

因id及name为文字, 其值均需加""
emp.id="22131"
emp.name="tang"

: strSQL = "insert into personnel values (emp) "
SQL语法有错误.请注意下列用法---
strSQL="insert into personnel values ('"+emp.ID+"', '"+emp.Name+"')"
: dbs.Execute strSQL
: dbs.Close

完整的程式如下:
in Module1
option Explicit
Type EmployeeRecord
ID As String * 6
Name As String * 9
End Type

Private Sub Command1_Click()
Dim dbs As Database
Dim strSQL As String
Dim emp As EmployeeRecord

Set dbs = DBEngine.Workspaces(0).OpenDatabase("c:\temp\service.mdb")
emp.ID = "22131"
emp.Name = "tang"
strSQL = "insert into personnel values (' " + emp.ID + " ', '" + emp.Name + "')"
dbs.Execute strSQL
dbs.Close
End Sub

Follow Ups:

- Re: 下列SQL那里错误 tsaitang 16:02:04 8/24/98 (0)