Re: Stored Procedures & Parameters Insert Problem
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Tue, 13 Mar 2007 07:09:11 -0400
incubusaurus@xxxxxxxxx wrote:
Hi,<snip>
I am using ADO, in a fairly simple VB 6.0 client based database
application, to manipulate an Access database. When I use a stored
procedure with parametised inputs to insert multiple records into a
table, I end up with the same values repeated for each record, despite
changing the value of the parameter. I suspect that somewhere along
the line, the parameter value is being cached. To simplify this post,
I have written a small procedure (see below) which produces the same
results as the application.
adoDBConn.Open "Provider=MSDataShape;" & _
Why use the MSDataShape provider? It is not needed for this activity. If
your application has need for the functionality provided by this provider,
You should consider using a separate Connection for that activity.
"Data Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "\Test.mdb"
adoCommand.ActiveConnection = adoDBConn
On Error Resume Next
adoDBConn.Execute "DROP PROCEDURE sp_InsertCount"
Why drop and recreate this procedure? It is contrary to the purpose of using
stored procedures: create it once and re-use it.
On Error GoTo 0
strCmd = "CREATE PROCEDURE sp_InsertCount AS "
This is now the time to get out of the habit of using "sp_" to prefix your
stored procedure names. it is not hurting you in Jet, but it will definitely
impair the efficiency of your procedures in SQL Server, which uses that
prefix to identify system stored procedures. When told to execute a query
with that prefix, SQL Server will waste time looking for the procedure in
the Master database, only looking for it in the current database when it is
not found in Master. Also, if you inadvertantly give te procedure the same
name as a system stored procedure, you may find yourself trying to figure
out errors due to the attempted execution of the wrong procedure.
strCmd = strCmd & "INSERT INTO TestCount (lngTestCount) "
strCmd = strCmd & "VALUES (@lngTestCount)"
adoDBConn.Execute strCmd
adoCommand.CommandText = "sp_InsertCount"
adoCommand.CommandType = adCmdStoredProc
Set prmADOParam = adoCommand.CreateParameter _
("@lngTestCount", adInteger, adParamInput, , Null)
adoCommand.Parameters.Append prmADOParam
' ** This produces 20 rows all with the same value **
For lngTestCount = 1 To 20
adoCommand.Parameters("@lngTestCount").Value = lngTestCount
It will be more efficient to use the prmADOParam object you went to such
trouble to create instead of going through the Parameters colection here.
prmADOParam .Value=lngTestCount
I would experiment with
1) changing the Provider to the Jet provider, eliminating the MSDataShape
provider. If that does not help:
2) setting the Command's Prepared property to True or False to see which
setting solves the issue.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: Stored Procedures & Parameters Insert Problem
- From: incubusaurus
- Re: Stored Procedures & Parameters Insert Problem
- References:
- ADO: Stored Procedures & Parameters Insert Problem
- From: incubusaurus
- ADO: Stored Procedures & Parameters Insert Problem
- Prev by Date: ADODB.Connection for OID (Oracle Internet Directory) from ASP classic
- Next by Date: Re: _com_error information
- Previous by thread: ADO: Stored Procedures & Parameters Insert Problem
- Next by thread: Re: Stored Procedures & Parameters Insert Problem
- Index(es):
Relevant Pages
|
|