2016-04-14 21 views
0

Öncelikle ben kodumu başladıKarakterler bulundu SQL Bildirimi Hata bitiminden sonra

  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() 

Ve bu hatayı alıyorum: bu yüzden şu anda bu çalışıyorum 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

Büyük olasılıkla, string bitlerini birbirine yapıştırmak yerine SQL Parametrelerini kullanırsanız sorun ortadan kalkacaktır. – Plutonix

+0

Hey, ben sadece "SQL Parameters" i googled ve benzer görünen bir şey bulamıyorum, bu konuda bilgimi katlayabileceğim veya bunun bir örneğini alabileceğim iyi bir bağlantınız var mı? –

+0

https://msdn.microsoft.com/en-us/library/system.data.oledb.oledbparameter(v=vs.110).aspx ve yaklaşık 1-2 milyon Qs burada – Plutonix

cevap

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() 
+0

Bir cevap genellikle bize neden bir cevap olduğunu söyler. Sql enjeksiyon ve biçimlendirme sorunlarını önlemek için parametreleri kullanın. – LarsTech

İlgili konular