0 Replies - 1262 Views - Last Post: 01 October 2012 - 08:50 PM Rate Topic: *---- 1 Votes

#1 123sujith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-October 12

Error on creating a table@myCommand.ExecuteNonQuery()

Posted 01 October 2012 - 08:50 PM

Imports System.Data.OleDb
Public Class Form2
Dim myTable As String


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnection As New OleDbConnection
Dim myCommand As New OleDbCommand
Dim mySQLString As String

myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\My.1st\[p\[p\user.accdb")
myTable = TextBox1.Text 'For assign the value of textbox1 to myTable

mySQLString = "CREATE TABLE myTable (Designation, Age,Address)" 'Creating a table with a name which is entered in textbox1
myConnection.Open()
myCommand = New OleDbCommand(mySQLString, myConnection)

myCommand.ExecuteNonQuery() 'ERROR OleDbException was unhandled {"Syntax error in field definition."}
MsgBox("Table Created")


mySQLString = "INSERT INTO myTable3 (Designation,Age,Address) VALUES (@Desi,@Age,@Add)"

myCommand = New OleDbCommand(mySQLString, myConnection)
myCommand.Parameters.AddWithValue("@Desi", TextBox2.Text)
myCommand.Parameters.AddWithValue("@Age", TextBox3.Text)
myCommand.Parameters.AddWithValue("@Add", TextBox4.Text)
myCommand.ExecuteNonQuery() 'ERROR OleDbException was unhandled {"Syntax error in field definition."}

MessageBox.Show("Value inserted.")

myConnection.Close()

End Sub
End Class

myCommand.ExecuteNonQuery()
'ERROR OleDbException was unhandled {"Syntax error in field definition."}

Is This A Good Question/Topic? 0
  • +

Page 1 of 1