|
-
Jun 10th, 2004, 01:06 PM
#1
Thread Starter
Addicted Member
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
-
Jun 10th, 2004, 01:44 PM
#2
Lively Member
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:
Dim SelectQuery As String = "SELECT * FROM ocuff1 WHERE ... (just look search for the record the same way that you update it)
Dim myReader As OleDb.OleDbDataReader
Dim QueryCmnd = New OleDb.OleDbCommand(SelectQuery, connection)
Dim done As Integer = 0
Dim teststr As String
While done = 0
myReader = myOleCommand.executereader()
teststr = myReader.Item("session_id")
If Not teststr = Nothing Then done = 1
End While
Then continue the rest of your code after that.
-
Jun 10th, 2004, 02:25 PM
#3
Frenzied Member
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.
-
Jun 10th, 2004, 04:38 PM
#4
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|