P
Paul
Hello,
Im trying to send a number of insert statements to SQL Server 2000 at
one time, using ADO.NET.
The code im using is pretty standard (see below) and the insert is
performed all fine and dandy.
Dim objCmd As SqlCommand
Dim dr As IDataReader
objCmd = SqlConnection1.CreateCommand()
objCmd.Transaction = SqlConnection1.BeginTransaction()
objCmd.CommandType = CommandType.Text
objCmd.CommandText = v_sSQL
dr = objCmd.ExecuteReader(CommandBehavior.Default)
the v_sSQL parameter contains SQL much like
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
(obviously these are dummy inserts - i dont usually create tables
named aa with a singular column aaa)
I'd like to know how many records each of the statements in my batch
affected (or created in the insert case). I was expecting in the above
case to have to call NextResult 3 times and get the .RecordsAffected
property value of 1 3 times as well. However this doesnt seem to be
the case. The first time i call .RecordsAffected I get a value of 3
(i.e. 3 records have been inserted) and the next call to NextResult
returns false i.e. no more resultsets. Whats going on here? How do i
distinguish between one statements results and another (much like
Query Analyser does) when posting a batch of statements to the server?
Another side issue I am having is with the InfoMessage handler which I
have implemented thus:
Private Sub SqlConnection1_InfoMessage(ByVal sender As Object, ByVal e
As System.Data.SqlClient.SqlInfoMessageEventArgs) Handles
SqlConnection1.InfoMessage
Dim objError As SqlError
For Each objError In e.Errors
m_sMessages = m_sMessages & objError.Message & vbCrLf
Next
End Sub
Again, im getting the messages all fine and dandy, however in this
case
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
PRINT 'Hello World'
I get the hello world message before i have a chance to interrogate
the DataReader for the results of the first two statements. Anybody
know a way of getting things to happen in the correct order when
working with multiple resultsets and server messages?
Thanks in advance.
Paul.
Im trying to send a number of insert statements to SQL Server 2000 at
one time, using ADO.NET.
The code im using is pretty standard (see below) and the insert is
performed all fine and dandy.
Dim objCmd As SqlCommand
Dim dr As IDataReader
objCmd = SqlConnection1.CreateCommand()
objCmd.Transaction = SqlConnection1.BeginTransaction()
objCmd.CommandType = CommandType.Text
objCmd.CommandText = v_sSQL
dr = objCmd.ExecuteReader(CommandBehavior.Default)
the v_sSQL parameter contains SQL much like
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
(obviously these are dummy inserts - i dont usually create tables
named aa with a singular column aaa)
I'd like to know how many records each of the statements in my batch
affected (or created in the insert case). I was expecting in the above
case to have to call NextResult 3 times and get the .RecordsAffected
property value of 1 3 times as well. However this doesnt seem to be
the case. The first time i call .RecordsAffected I get a value of 3
(i.e. 3 records have been inserted) and the next call to NextResult
returns false i.e. no more resultsets. Whats going on here? How do i
distinguish between one statements results and another (much like
Query Analyser does) when posting a batch of statements to the server?
Another side issue I am having is with the InfoMessage handler which I
have implemented thus:
Private Sub SqlConnection1_InfoMessage(ByVal sender As Object, ByVal e
As System.Data.SqlClient.SqlInfoMessageEventArgs) Handles
SqlConnection1.InfoMessage
Dim objError As SqlError
For Each objError In e.Errors
m_sMessages = m_sMessages & objError.Message & vbCrLf
Next
End Sub
Again, im getting the messages all fine and dandy, however in this
case
insert aa (aaa) values('aa')
insert aa (aaa) values('aa')
PRINT 'Hello World'
I get the hello world message before i have a chance to interrogate
the DataReader for the results of the first two statements. Anybody
know a way of getting things to happen in the correct order when
working with multiple resultsets and server messages?
Thanks in advance.
Paul.