Results 1 to 4 of 4

Thread: Easy Question....Probably

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    Easy Question....Probably

    I am using the follwing code to insert things into a Access 2003 DB:

    Code:
      Dim strSQL As StringBuilder
                    Dim strconn As String
                    Dim connection As New OleDb.OleDbConnection
                    strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbplace
    
                                              connection.ConnectionString = strconn
                    connection.Open()
    
    
                    Dim command As New OleDb.OleDbCommand
                    command.Connection = connection
    
                 
                        command.CommandText = "INSERT Into ocuff1(ocuff1,CYCLE_RAT_1_ID,session_id ) Values ('" & rat1ocuff.ToString & "'," & CYCLE_RAT_1_ID & ",'" & cycleid & "')"
                        command.ExecuteNonQuery()
    Is there an easy way to see or to verify that this is completed?
    In other words I want to know that it is done before I move on.

    Thanks,
    Bebandit

  2. #2
    Lively Member
    Join Date
    Nov 2003
    Location
    Chicagoland
    Posts
    92
    What do you mean "when its done"?

    You could just run a loop a select statement to see if the fields have been filled. Something like:

    VB Code:
    1. Dim SelectQuery As String = "SELECT * FROM ocuff1 WHERE ... (just look search for the record the same way that you update it)
    2. Dim myReader As OleDb.OleDbDataReader
    3. Dim QueryCmnd = New OleDb.OleDbCommand(SelectQuery, connection)
    4. Dim done As Integer = 0
    5. Dim teststr As String
    6. While done = 0
    7.      myReader = myOleCommand.executereader()
    8.      teststr = myReader.Item("session_id")
    9.      If Not teststr = Nothing Then done = 1
    10. End While

    Then continue the rest of your code after that.

  3. #3
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618
    You could do a try, catch statement. I haven't tried it with Access and the ole, but I know with SQL Server if you send a bad SQL Statement it tosses an exception.
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  4. #4
    Fanatic Member
    Join Date
    May 2002
    Posts
    746

    Re: Easy Question....Probably

    Originally posted by bebandit
    Is there an easy way to see or to verify that this is completed?
    In other words I want to know that it is done before I move on.
    Is there a specific reason you want to check on the state of the operation? That is, is your next step dependent on those values being inserted? If so, there is often a lag between running a command and access updating for update/insert/delete statements - you can often receive a message that the statement has run successfully but not see the value in access for some [relatively short] amount of time.

    Also, running cmd.ExecuteNonQuery() returns an integer value of rows affected - -1 indicating an error.

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