I've got this code. But I keep getting an INSERT INTO error when I try to insert a new field into the database
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim recordsadded As Integer
Dim strSQLString1, strSQLString2, strSQLString As String
strSQLString1 = "INSERT INTO tblParts (PartName, PartPrice, Part Supplier) "
strSQLString2 = "VALUES ('" & txtPartName.Text & "','" & txtPartPrice.Text & "','" & txtPartSupplier.Text & "')"
strSQLString = strSQLString1 + strSQLString2
MessageBox.Show(strSQLString)
Dim NewPartTableAdaptor As New DataTable
Try
Dim dbCommand As New OleDbCommand
dbCommand.Connection = LogInForm.dbConnection
dbCommand.CommandType = CommandType.Text
dbCommand.CommandText = strSQLString
recordsadded = dbCommand.ExecuteNonQuery()
MessageBox.Show(recordsadded)
Catch ex As Exception
MessageBox.Show(ex.Message & "-" & ex.Source)
End Try
End Sub
My 3 datatypes are text values, and I have anoter form adding entries to my database in another table, which are all text values.
Any ideas?
Lucy
5 Replies - 1817 Views - Last Post: 13 April 2010 - 05:42 AM
#1
Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 01:48 AM
Replies To: Help with INSERT INTO statement in VB.NET using SQL
#2
Re: Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 01:57 AM
what is the error.
This post has been edited by NoBrain: 13 April 2010 - 01:59 AM
#3
Re: Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 02:08 AM
Syntax Error in INSERT INTO statement.-Microsoft JET Database Engine
Syntax Error in INSERT INTO statement.-Microsoft JET Database Engine
Syntax Error in INSERT INTO statement.-Microsoft JET Database Engine
#4
Re: Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 02:47 AM
try without using ' in your values section and check if there is no reserved word in SQL that you use in your table Supplier maybe one
#5
Re: Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 05:15 AM
Enclose Part Supplier inside brackets,
INSERT INTO tblParts (PartName, PartPrice, [Part Supplier])
Spaces aren't allowed without enclosing them in brackets.
INSERT INTO tblParts (PartName, PartPrice, [Part Supplier])
Spaces aren't allowed without enclosing them in brackets.
#6
Re: Help with INSERT INTO statement in VB.NET using SQL
Posted 13 April 2010 - 05:42 AM
If your Column Name contains a space it must be enclosed in square brackets (PartName, PartPrice, [Part Supplier])
Can i ask though. Why are you doing it in 2 parts (or 3 parts).
You could just
Also is this a ms access database or another type. here is an example if you were doing ms access with oledb.
Can i ask though. Why are you doing it in 2 parts (or 3 parts).
You could just
strSQLString = "INSERT INTO tblParts (PartName, PartPrice, [Part Supplier]) VALUES ('" & txtPartName.Text & "','" & txtPartPrice.Text & "','" & txtPartSupplier.Text & "')"
Also is this a ms access database or another type. here is an example if you were doing ms access with oledb.
dataAdapter.InsertCommand = New OleDbCommand("INSERT INTO Project (PartName, PartPrice, [Part Supplier]) VALUES (@Name, @Price, @Supplier)")
dataAdapter.InsertCommand.Connection = connectionString
dataAdapter.InsertCommand.Parameters.AddWithValue("@Name", txtPartName.Text)
dataAdapter.InsertCommand.Parameters.AddWithValue("@Price", txtPartPrice.Text)
dataAdapter.InsertCommand.Parameters.AddWithValue("@Supplier", txtPartSupplier.Text)
This post has been edited by JoshD: 13 April 2010 - 05:51 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|