title: Trying to Insert Text to Access Database with ExecuteNonQueryin VB
body: <p>I'm working on this feature were i save text from a textbox on my form to a access database file. With the click on my "store" button I want to save the text in the corresponding textbox fields to the fields in my access database for searching and retrieving purposes. Im doing this in VB</p>
  
  <p>The problem I run into is the INSERT TO error with my "store" button
  Any help or insight as to why im getting error would be greatly appreciated. </p>
  
  <p>here is my code:</p>
  
  <pre><code>Dim con As System.Data.OleDb.OleDbConnection
  Dim cmd As System.Data.OleDb.OleDbCommand
  Dim dr As System.Data.OleDb.OleDbDataReader
  Dim sqlStr As String
  
  Private Sub btnStore_Click(sender As Object, e As EventArgs) Handles btnStore.Click
  
      con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Eric\Documents\SPC1.2.accdb")
      con.Open()
  
      MsgBox("Initialized")
  
      sqlStr = "INSERT INTO Master FADV Calll info  (First Name, Last Name, 
         Phone Number, Email, User Id) values (" &amp; txtFirstName.Text &amp; " ' ,'" &amp;
         txtLastName.Text &amp; "','" &amp; txtPhone.Text &amp; "', '" &amp; txtEmail.Text &amp; "', '" &amp;
         txtUserID.Text &amp; "', '" &amp; txtOtherOptionTxt.Text &amp; "','" 
         &amp; txtCallDetail.Text &amp; "');"
  
      cmd = New OleDb.OleDbCommand(sqlStr, con)
      cmd.ExecuteNonQuery()   &lt;------- **IM RECIVING THE ERROR HERE** 
      MsgBox("Stored")
      ''pass ther parameter as sq; query, con " connection Obj)"
  
      con.Close()
  </code></pre>
  
  <hr>
  
  <p>So I tried to clean up my code a little, I didn't use paramerters like you recommended yet so maybe that is why I am still receiving the error. I figured this would work since it was a little cleaner</p>
  
  <pre><code>sqlStr = "INSERT INTO Master FADV Calll info(First Name, Last Name, Phone Number,
   Email, User Id,Notes) values (@First Name, @Last Name, @Phone Number,@ Email,
   @UserId,@Notes)"
  
  
      cmd = New OleDb.OleDbCommand(sqlStr, con)
      cmd.ExecuteNonQuery()'
  </code></pre>
  
  <p>Now by parameters do you mean something along the lines of this
  'cmdInsert.Parameters.Add("@FirstName", Data.SqlDbType.NVarChar).Value = FirstName'</p>
  
  <hr>
  
  <p>im still getting this crazy error its making me want to bang my head against a wall. I do apologize for bugging you on such a meager issue, but please bear with me. I am receiving this error message here is my code
  Syntax error (missing operator) in query expression '@First Name'. </p>
  
  <p>but even before I was still getting an input error at the cmd.ExecuteNonQuery() line. </p>
  
  <p>'Dim SQL As String = "INSERT INTO [Master FADV Calll info] Values  (@First Name, @Last Name, @Phone Number,)"</p>
  
  <pre><code>    Using cmd As New OleDbCommand(SQL, con)
          cmd.Parameters.AddWithValue("@First Name", txtFirstName.Text)
          cmd.Parameters.AddWithValue("@Last Name", txtLastName.Text)
          cmd.Parameters.AddWithValue("@Phone Number", txtPhone.Text)
          ' etc
  
          cmd.ExecuteNonQuery()
  
      End Using'
  </code></pre>
  
  <hr>
  
  <p>I fianaly got it to work. here is my code</p>
  
  <p>' con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Eric\Documents\Fadv.accdb")
          con.Open()</p>
  
  <pre><code>    Dim SQL As String = "INSERT INTO [info] ([FirstName], [LastName], [Phone#]) Values (?, ?, ?)"
  
  
      Using cmd As New OleDbCommand(Sql, con)
  
          cmd.Parameters.AddWithValue("@p1", txtFirstName.Text)
          cmd.Parameters.AddWithValue("@p2", txtLastName.Text)
          cmd.Parameters.AddWithValue("@p3", txtPhone.Text)
          ' etc
  
          cmd.ExecuteNonQuery()
  
          con.Close()
      End Using
  </code></pre>
  
  <p>'</p>