Results 1 to 2 of 2
  1. #1
    Cined is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Apr 2010
    Posts
    9

    Inserting into a database

    Hello,

    I've written the following code to add a new record to a database:

    Code:
    Public Shared Sub AddTopicUser(ByVal UserID As Integer, ByVal TopicCode As String)
    
            Dim RowsAffected As Integer
    
            Dim ATUDCONN As New OleDbConnection
            ATUDCONN.ConnectionString = DBCONNSTR
    
            Dim ATUDCMD As New OleDbCommand("INSERT INTO tblSubscriptions (UserID, TopicCode, Completed) Values (@UserID, @TopicCode, @Completed)", ATUDCONN)
    
            Dim Completed As String = "No"
    
            With ATUDCMD.Parameters
                .AddWithValue("@UserID", UserID)
                .AddWithValue("@TopicCode", TopicCode)
                .AddWithValue("@Completed", Completed)
            End With
    
            Try
    
                ATUDCONN.Open()
    
                RowsAffected = ATUDCMD.ExecuteNonQuery()
    
                ATUDCONN.Close()
                ATUDCONN.Dispose()
    
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
    
        End Sub
    I recieve no errors from the code, but when i open the database after - the record has not been added.

    I have checked that the values being passed as parameters to the function are valid. I was curious as to whether I was formatting the OleDbCmd correctly, but the value of RowsAffected is 1 at runtime which means that it's communicating with the database.

    Any ideas when they're not being added to the db?



    Ty.

  2. #2
    Gerry is offline Rusty Developer
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Kings Mountain, NC
    Posts
    33
    I'm not familiar with OLE connections, but perhaps it requires something similar to the UPDATE method to actually write the data over the connection?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Inserting/Updating
    By detlion1643 in forum Access
    Replies: 1
    Last Post: 02-26-2010, 07:25 PM
  2. Inserting data into Access database
    By bhanu in forum Access
    Replies: 1
    Last Post: 12-21-2009, 09:07 AM
  3. Inserting a picture
    By Carenas in forum Forms
    Replies: 0
    Last Post: 01-03-2009, 05:09 PM
  4. Inserting data through forms
    By nivi30 in forum Forms
    Replies: 1
    Last Post: 12-17-2008, 07:57 AM
  5. Inserting data in new colums
    By wasim_sono in forum Queries
    Replies: 2
    Last Post: 02-28-2006, 01:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums