473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Timing for ExecuteNonQuery

jdb
Hi,

I am adding a record to the database using an ExecuteNonQuery, which adds
without problem. Now after the record is added I run a method passing in
some info as well as the curretnly opened connection (byRef cn as
OleDbConnection). Am using an Access 2000 database. Now in this new method I
create a command object using the passed in connection object. I then create
a DataReader to read the database that has the record added in the
ExecuteNonQuery section. Now if I step through my program everything works,
but if I let it run the dataReader doesn't see the newly created record!! If
I add a for loop (1000 steps, sometimes longer) the DataReader see the
record. So I can I be sure that the record added is actually in the database
before the dataReader attempts to read the database? By the way the
RecordsAffected in the ExecuteNonQuery does show 1.

Any ideas?

Thanks
John

Nov 21 '05 #1
2 1514
You need to post the relevant pieces of code.

"jdb" <jd*@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
Hi,

I am adding a record to the database using an ExecuteNonQuery, which
adds
without problem. Now after the record is added I run a method passing in
some info as well as the curretnly opened connection (byRef cn as
OleDbConnection). Am using an Access 2000 database. Now in this new
method I
create a command object using the passed in connection object. I then
create
a DataReader to read the database that has the record added in the
ExecuteNonQuery section. Now if I step through my program everything
works,
but if I let it run the dataReader doesn't see the newly created record!!
If
I add a for loop (1000 steps, sometimes longer) the DataReader see the
record. So I can I be sure that the record added is actually in the
database
before the dataReader attempts to read the database? By the way the
RecordsAffected in the ExecuteNonQuery does show 1.

Any ideas?

Thanks
John

Nov 21 '05 #2
jdb
Sorry here is the code in question

Private Function SaveNewSteps() As Boolean
Dim myCN As New OleDbConnection(myConnectionString)
Dim cmd As New OleDbCommand
Dim SQL As String
Dim rID As Long
Dim RecordsAffected As Integer
Dim i As Integer
Dim sc As Byte
Dim retval As Boolean = True

cmd.Connection = myCN
myCN.Open()

sc = CType(1, Byte) + m_StepCode ' Take step code and add 1 to it
SQL = "INSERT INTO ztblCustomRequirementSteps (ProjectID,
RequirementID, StepNum, " & _
"StepName, StepDesc, StepCode, StepInternal)" & _
" VALUES " & _
"(" & m_ProjID & "," & m_reqID & "," & _
m_StepNum & ",'" & _
Replace(txtNewStep.Text, "'", "''") & "" & "','" & _
Replace(txtNewStepDesc.Text, "'", "''") & "" & "'," & _
sc & ",True)"
cmd.CommandText = SQL

Try
RecordsAffected = cmd.ExecuteNonQuery()
' we need to add the timeframe for this new step to tblTimeframe
If RecordsAffected > 0 Then

' Need to update the StepCode values
updateSteps(m_reqID, m_StepNum, myCN)

End If
Catch ex As Exception
retval = False
MessageBox.Show("Error Adding New Steps:" & ControlChars.CrLf &
ControlChars.CrLf & ex.ToString & ControlChars.CrLf & "An exception of type "
& ex.GetType().ToString() & _
" was encountered while adding new steps.",
"Adding New Steps")
Finally
myCN.Close()
End Try
Return retval
End Function

Private Sub updateSteps(ByVal rID As Long, ByVal lNum As Long, ByRef fCN
as OleDbConnection)
' Create the Command object
Dim cnS As New OleDbConnection(myConnectionString)
Dim cmdSQL As New OleDbCommand("SELECT * FROM
ztblCustomRequirementSteps where ProjectID = " & m_ProjID & _
" AND RequirementID = " & rID & _
" AND StepNum = " & lNum & " ORDER BY
StepCode, TempStepCode DESC", fCN)
Dim cmdInsert As New OleDbCommand
Dim SQL As String
Dim RecordsAffected As Integer
Dim sId As Long
Dim sCode As Byte
Dim tCode As Byte
Dim bReorder As Boolean = False

cmdInsert.Connection = cnS
cnS.Open()

' Dummy loop to make sure that all data has been written
' If this loop is not present the following DataReader will not see
the record
' that was added in this calling function SaveNewSteps()
Dim i as Integer
For i = 0 to 1000
debug.WriteLine (i)
Next

Dim rdr As OleDbDataReader =
cmdSQL.ExecuteReader(CommandBehavior.CloseConnecti on)
With rdr
While .Read
sId = .GetValue(0) '
Read StepID
sCode = .GetValue(6) '
StepCode
If Not IsDBNull(.GetValue(7)) Then tCode = .GetValue(7)
'Temp Step Code
If bReorder Then
' We have reached a point where steps need to be reordered
SQL = "UPDATE ztblCustomRequirementSteps SET
StepCode=StepCode + 1 WHERE " & _
"StepID = " & sId
cmdInsert.CommandText = SQL
Try
RecordsAffected = cmdInsert.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Else
' If the TempStepCode is not 1, do nothing
If tCode = 1 Then
' Reorder all following records
bReorder = True
SQL = "UPDATE ztblCustomRequirementSteps SET
TempStepCode = 0 WHERE " & _
"StepID = " & sId
cmdInsert.CommandText = SQL
Try
RecordsAffected = cmdInsert.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End If
End If
End While
End With
rdr.Close()
cnS.Close()
End Sub

John

"Marina" wrote:
You need to post the relevant pieces of code.

"jdb" <jd*@discussions.microsoft.com> wrote in message
news:EF**********************************@microsof t.com...
Hi,

I am adding a record to the database using an ExecuteNonQuery, which
adds
without problem. Now after the record is added I run a method passing in
some info as well as the curretnly opened connection (byRef cn as
OleDbConnection). Am using an Access 2000 database. Now in this new
method I
create a command object using the passed in connection object. I then
create
a DataReader to read the database that has the record added in the
ExecuteNonQuery section. Now if I step through my program everything
works,
but if I let it run the dataReader doesn't see the newly created record!!
If
I add a for loop (1000 steps, sometimes longer) the DataReader see the
record. So I can I be sure that the record added is actually in the
database
before the dataReader attempts to read the database? By the way the
RecordsAffected in the ExecuteNonQuery does show 1.

Any ideas?

Thanks
John


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dkalsow | last post by:
Good Morning, I get the following error when trying to add a record to and access table: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll. The code...
10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
10
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void...
7
by: jamie | last post by:
hey all, I am attempting to do motion control for a final project, but I have a concern.... For motion control, timing is everyting, the better it is, the better it works. Currently I am...
1
by: Novice | last post by:
Hi all, I'm at my wit's end on trying to insert some timing code into the server side code that parses the hashed data contained in the hidden field being submitted to the server I've tried...
3
by: gregory_may | last post by:
I have an application where I am using a System Thread to capture the screen & Broadcast it to clients. Its "working", but the timing on the background thread gets wildly erratic at times. Some...
3
by: keithb | last post by:
What can I put in a stored procedure to control what gets returned by command.ExecuteNonQuery()? I already tried this: param = comm.CreateParameter(); param.ParameterName = "@Success"; ...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.