2番目の値の単一引用符を見逃しました。これを試して、
command = New OleDb.OleDbCommand("INSERT INTO Artikels VALUES('1','" + txtOmsch.Text + _
"','" + txtCat.Text + "','" + txtAPE.Text + _
"','" + txtMarge.Text + "','" + txtVPE.Text + _
"','" + txtEen.Text + "','" + txtLen.Text + _
"','" + txtBreed.Text + "','" + txtDiep.Text + _
txtOmsch.Text + "');")
あなたのコードはSQLインジェクションに対して脆弱です。使用しているのでパラメータ化されたクエリを使用してくださいADO.NET
。以下のこのコードを試してみてください。
Dim con As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database1.accdb"
Dim query As String = "INSERT INTO Artikels VALUES(@val1, @Omsch, @Cat, @Ape, @VPE, @Een, @len, @breed, @diep,@Omsch)")
Using connOledb As New OleDbConnection(con)
Using command As New OleDbCommand()
With command
.Connection = con
.CommandType = CommandType.Text
.CommandText = query
.Parameters.AddWithValue("@val1",1)
.Parameters.AddWithValue("@Omsch",txtOmsch.Text)
.Parameters.AddWithValue("@Cat",txtCat.Text)
.Parameters.AddWithValue("@Ape",txtAPE.Text)
.Parameters.AddWithValue("@VPE",txtVPE.Text)
.Parameters.AddWithValue("@Een",txtEen.Text )
.Parameters.AddWithValue("@len",txtLen.Text)
.Parameters.AddWithValue("@breed",txtBreed.Text)
.Parameters.AddWithValue("@diep",txtDiep.Text)
End with
Try
connOledb.Open()
command.ExecuteNonQuery()
Catch(ex as OleDBException)
Msgbox(ex.Message.Tostring())
End Try
End Using
End Using
またAdd
.Add("@Omsch", OleDbType.VarChar, 30).Value = txtOmsch.Text