Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

sql - 我的代码在此行出现错误(I am getting error on this line in my code)

I am still developing my School management system.

(我仍在开发学校管理系统。)

I want to create a multiple username and password for my system.

(我想为我的系统创建多个用户名和密码。)

But I am getting a Runt ime error 31314 on the Insert statement.

(但是我在插入语句上收到了Runt ime错误31314。)

CurrentDb.Execute "INSERT INTO users(Username,Password,Email,Mobile,UserType) VALUES('" & Me.uname & "', '" & Me.upass & "', '" & Me.uemail & "', '" & Me.umobile & "', '" & Me.utype & "',)"
  ask by Levis kerzuah translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can/should use a temporary parameter query:

(您可以/应该使用临时参数查询:)

  • The sql statement looks much clearer

    (sql语句看起来更加清晰)

  • It takes care of datytypes (no ' s nacessary

    (它负责datytypes(无'小号nacessary)

  • It prevents SQL Injection

    (它防止SQL注入)

With CurrentDb().CreateQueryDef(vbNullString, _
        "INSERT INTO users (Username, [Password], Email, Mobile, UserType) VALUES (p1, p2, p3, p4, p5)")
    .Parameters("p1").Value = Me.uname
    .Parameters("p2").Value = Me.upass
    .Parameters("p3").Value = Me.uemail
    .Parameters("p4").Value = Me.umobile
    .Parameters("p5").Value = Me.utype
    .Execute dbFailOnError
End With

If you want you can rename the parameters p1 to p5 to more describing names ie pUName and so on.

(如果需要,可以将参数p1p5重命名为更多描述性名称, pUName等。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...