我在vba excel的代码中使用了这个insert语句,但是我无法将其分成多行
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & " _
,'" & txtContractStartDate.Value & "' _
,'" & txtSeatNo.Value & "' _
,'" & txtFloor.Value & "','" & txtLeaves.Value & "')"
给出错误“预期结束声明”。 Plz帮助。
答案 0 :(得分:40)
您不能在字符串中使用VB行继续符。
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & _
"','" & txtContractStartDate.Value & _
"','" & txtSeatNo.Value & _
"','" & txtFloor.Value & "','" & txtLeaves.Value & "')"
答案 1 :(得分:10)
你可以简单地在多个步骤中创建你的字符串,有点多余,但它可以保持代码的可读性并在调试或编辑时保持健全
SqlQueryString = "Insert into Employee values("
SqlQueryString = SqlQueryString & txtEmployeeNo.Value & " ,"
SqlQueryString = SqlQueryString & " '" & txtEmployeeNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtContractStartDate.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtSeatNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtContractStartDate.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtSeatNo.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtFloor.Value & "',"
SqlQueryString = SqlQueryString & " '" & txtLeaves.Value & "' )"
答案 2 :(得分:5)
如果多行的长字符串让您感到困惑。然后你可以安装mz-tools addin这是一个免费软件,并有实用程序为你分割线。
如果您的字符串如下所示
SqlQueryString = "Insert into Employee values(" & txtEmployeeNo.Value & "','" & txtContractStartDate.Value & "','" & txtSeatNo.Value & "','" & txtFloor.Value & "','" & txtLeaves.Value & "')"
只需选择字符串>右键单击VBA IDE>选择MZ-tools>分割线
答案 3 :(得分:-2)
我知道这已经是超级骗子了,但是从Visual Basic 14开始,几乎没有人会找这个,Vb支持插值。太酷了!
示例:
SQLQueryString = $"
Insert into Employee values(
{txtEmployeeNo},
{txtContractsStartDate},
{txtSeatNo},
{txtFloor},
{txtLeaves}
)"