SQL语句错误结束后找到的字符

时间:2016-04-14 16:06:56

标签: vb.net access-vba

首先,我用以下代码开始了我的代码:

            Comm2 = "INSERT INTO [Results]" _
                 & "([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs], [TargetFilter])" _
                 & " values('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "',  '" & kVp & "',  '" & mAs & "',  '" & TargetFilter & "')"

            Comm3 = "INSERT INTO [Test]" _
                 & "([TestID], [Date], [MachineID], [RadiographerID])" _
                 & " values('" & CInt(NewRID) & " ', '" & todaysdate & " ', '" & 1 & " ', '" & UserID & " ',)"

然而,由于这些表在数据库中是相关的,因此不能同时更改它们,因此我没有工作,所以我目前正在尝试这样做:

            Comm2 = "INSERT INTO [Results] ([ResultsID],[TestID],[Tickness],[SNR],[STD],[M1],[M2],[kVp],[mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "',  '" & kVp & "',  '" & mAs & "',  '" & TargetFilter & "');" _
                & "INSERT INTO [Test] ([TestID], [Date[, [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CStr(UserID) & "')"
            OleDbInsertCommand.Connection = conn
            OleDbInsertCommand.CommandText = Comm2
            adapter2.InsertCommand = OleDbInsertCommand
            adapter2.InsertCommand.ExecuteNonQuery()

我收到此错误: https://gyazo.com/36aa32cbfb0f54bbe571f6a9384114e1

            Comm2 = "INSERT INTO [Results] ([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "',  '" & kVp & "',  '" & mAs & "',  '" & TargetFilter & "')"
            comm3 = " INSERT INTO [Test] ([TestID], [Date], [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CInt(UserID) & "')"

            OleDbInsertCommand.Connection = conn
            OleDbInsertCommand.CommandText = comm3
            adapter2.InsertCommand = OleDbInsertCommand
            adapter2.InsertCommand.ExecuteNonQuery()
            OleDbInsertCommand.CommandText = Comm2
            adapter2.InsertCommand = OleDbInsertCommand
            adapter2.InsertCommand.ExecuteNonQuery()

1 个答案:

答案 0 :(得分:1)

        Comm2 = "INSERT INTO [Results] ([ResultsID], [TestID], [Thickness], [SNR], [STD], [M1], [M2], [kVp], [mAs],[TargetFilter]) VALUES('" & CInt(NewRID) & " ', '" & CInt(NewRID) & " ', '" & Thickness & "', '" & SNR & "', '" & STD & "','" & M1 & "', '" & M2 & "',  '" & kVp & "',  '" & mAs & "',  '" & TargetFilter & "')"
        comm3 = " INSERT INTO [Test] ([TestID], [Date], [MachineID], [RadiographerID]) VALUES('" & CInt(NewRID) & " ', '" & CDate(todaysdate) & " ', '" & CInt(MachineID) & "', '" & CInt(UserID) & "')"

        OleDbInsertCommand.Connection = conn
        OleDbInsertCommand.CommandText = comm3
        adapter2.InsertCommand = OleDbInsertCommand
        adapter2.InsertCommand.ExecuteNonQuery()
        OleDbInsertCommand.CommandText = Comm2
        adapter2.InsertCommand = OleDbInsertCommand
        adapter2.InsertCommand.ExecuteNonQuery()