Results 1 to 4 of 4

Thread: Using executeNonQuery to execute an INSERT stmt [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2003
    Location
    Savannah, GA
    Posts
    100

    Using executeNonQuery to execute an INSERT stmt [RESOLVED]

    I am attempting to use the executeNonQuery method of a
    command object to execute an insert SQL statement on a table in
    an Access database. I have successfully used executeNonQuery
    to perform an Update to a table but I can't seem to get this one
    to work. Here is my code, I have printed the generated query
    and tested it in access and the query works fine, must be
    something with my VB code. I'm new to .NET so I'm not seeing
    the problem. Any help is appreciated. Here is my code.

    VB Code:
    1. Private Sub Insert_Row()
    2.         Dim strSQL As String
    3.  
    4.         Dim strconn As String
    5.         Dim connection As New OleDb.OleDbConnection
    6.  
    7.         Dim a() As String = cmbExpenseAccount.SelectedItem.Split()
    8.  
    9.         strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = S:\20YRLongRangePlan\CapitalLogistics.mdb"
    10.  
    11.         strSQL = "INSERT INTO tblProjects VALUES(" & projectID
    12. & ", '', '', '" & a(0) & "', " & Chr(34) & txtDescription.Text & Chr(34)
    13. & ", " & Chr(34) & txtManufacturer.Text & Chr(34) & ", '', '', " & Chr
    14. (34) & txtProjectLife.Text & Chr(34) & ", " & Chr(34) &
    15. cmbReviewYear.SelectedItem & Chr(34) & ", " & Chr(34) &
    16. cmbReplacementYear.SelectedItem & Chr(34) & ", " & Chr(34) &
    17. txtArchitectComments.Text & Chr(34) & ", " & Chr(34) &
    18. cmbArchitect.SelectedItem & Chr(34) & ", '', '', '', '', " & Chr(34) &
    19. cmbGrant.SelectedItem & Chr(34) & ", '', '', '', '', '', '', '', '', " &
    20. Me.projDesc & ");"
    21.  
    22.  
    23.  
    24.         connection.ConnectionString = strconn
    25.         connection.Open()
    26.  
    27.  
    28.         Dim command As New OleDb.OleDbCommand
    29.  
    30.  
    31.         command.CommandText = strSQL
    32.  
    33.         command.Connection = connection
    34.  
    35.         command.ExecuteNonQuery()
    36.  
    37.         MsgBox("Project Information Inserted Successfully.", MsgBoxStyle.Information)
    38.  
    39. End Sub

    With an error occuring on the command.ExecuteNonQuery() line.

    Thanks in advance for any help.
    Last edited by ERage; Dec 20th, 2003 at 06:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width