# Re: 下列SQL那里错误

Posted by tsaitang on August 24, 1998 at 16:02:04:

In Reply to: Re: 下列SQL那里错误 posted by Stone on August 13, 1998 at 15:27:58:

: : 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
感谢 stone 回答

Follow Ups: