Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Access VB.NET 2007
I am new to programming and have been working on a project to insert values from textboxes and checkboxes located on my windows form to an access 2007 database. I keep getting this error when I execute the code.
 
My code is attached and I can submit the stack trace if necessary... any information that could help me figure this out would be greatly appreciated.. Thank you in advance!
 
PUBLIC CLASS
 
    Dim connOLEDB As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\EP\EP.accdb;")
 
    Dim cmdOLEDB As New OleDbCommand
 
    Dim cmd As New OleDbCommand
 
PRIVATE SUB
 
Dim insertQUERY As String
 
        connOLEDB.Open()
 
        insertQUERY = "Insert Into Email_Settings(smtpserver, fromaddress, username, [password], port, ssltls, default) values(@smtpserver, @fromaddress, @username, @password, @port, @ssltls, @default)"
 
        cmd = New OleDbCommand(insertQUERY, connOLEDB)
        cmd.Parameters.AddWithValue("@smtpserver", gmailsettingsForm.gmailsmtp.Text)
        cmd.Parameters.AddWithValue("@fromaddress", gmailsettingsForm.gmailaddress.Text)
        cmd.Parameters.AddWithValue("@username", gmailsettingsForm.gmailusername.Text)
        cmd.Parameters.AddWithValue("@password", gmailsettingsForm.gmailpassword.Text)
        cmd.Parameters.AddWithValue("@port", gmailsettingsForm.gmailserverport.Text)
        cmd.Parameters.AddWithValue("@ssltls", gmailsettingsForm.gmailSSLCheckBox.Checked.ToString())
        cmd.Parameters.AddWithValue("@default", gmailsettingsForm.gmaildefault.Checked.ToString())
 
        cmdOLEDB.ExecuteNonQuery()***(Error Presents Here)***
        connOLEDB.Close()
        Me.Close()
        gmailsettingsForm.Show()
Posted 14-Oct-12 17:01pm
Edited 14-Oct-12 17:56pm
v2
Comments
Wes Aday at 14-Oct-12 22:05pm
   
You have defined two different OleDbCommand objects and the one that you are getting the error on is the one that you have done nothing with.
Milchyboy at 14-Oct-12 23:07pm
   
Thank you for that I really beat myself up on that one.... I also fixed the Reserved Keyword [default]...
 
Thank You WES ADAY!!!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Public:
 
  Dim connOLEDB As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & "Data Source=C:\EP\EP.accdb;")
    
Dim cmd As New OleDbCommand
 
Sub:
 
Dim insertQUERY As String
 
        connOLEDB.Open()
 
        insertQUERY = "Insert Into Email_Settings(smtpserver, fromaddress, username, emailpass, port, ssltls, isdefault) values(@smtpserver, @fromaddress, @username, @emailPass, @port, @ssltls, @isDefault)"
 
        cmd = New OleDbCommand(insertQUERY, connOLEDB)
        cmd.Parameters.AddWithValue("@smtpserver", gmailsettingsForm.gmailsmtp.Text)
        cmd.Parameters.AddWithValue("@fromaddress", gmailsettingsForm.gmailaddress.Text)
        cmd.Parameters.AddWithValue("@username", gmailsettingsForm.gmailusername.Text)
        cmd.Parameters.AddWithValue("@password", gmailsettingsForm.gmailpassword.Text)
        cmd.Parameters.AddWithValue("@port", gmailsettingsForm.gmailserverport.Text)
        cmd.Parameters.AddWithValue("@ssltls", gmailsettingsForm.gmailSSLCheckBox.Checked)
        cmd.Parameters.AddWithValue("@default", gmailsettingsForm.gmaildefault.Checked)
 
        cmd.ExecuteNonQuery()
        connOLEDB.Close()
        Me.Close()
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 15 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100