|
-
August 19th, 2010, 08:46 AM
#3
Re: VB and adding data to a database
Hello all,
I've been busy trying to get this implemented in my program but am having a problem trying to get the data added to the database.
The program will run without problems but as soon as I call the button click event procedure I get an error "Command text was not set for the command object".
Code:
Module ModDB
Public Function test() As OleDb.OleDbConnection
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database1.accdb;Persist Security Info=False;"
dbSource = "Data Source = C:/customerInfo1.accdb"
con.ConnectionString = dbProvider & dbSource
'con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\customerInfo1.accdb;Persist Security Info=False;" & Application.StartupPath.ToString & "customerInfo1.accdb")
Return con
con = Nothing
End Function
Public bool As Boolean
Public da As OleDb.OleDbDataAdapter
Public dt As New DataTable
Public i As Int16
Public cmd As OleDb.OleDbCommand
Public da1 As OleDb.OleDbDataAdapter
Public strSQL As String
Public CB As OleDb.OleDbCommandBuilder
Public con = ModDB.test
End Module
'This is in the button click method
Try
Dim connString As String
Dim cmd As OleDb.OleDbCommand
Dim testDB = ModDB.test
connString = "INSERT INTO customerINfo (FullName, Address1, PhoneNumber)VALUES (trim(txtName.text), trim(txtAddress.text),trim(txtPHone.text))"
cmd = New OleDb.OleDbCommand(strSQL)
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
I'm still very new to this so if I'm going at this the completely wrong way please point me in the right direction. Is this error telling me to use an SQL command? I only want to enter data into the database and then later have a report that has all the users that bought tickets show up in a print preview.
Thank you in advance.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|