Solved

ADO.NET passing SQL InputOutput parameter problem

Posted on 2004-09-09
12
680 Views
Last Modified: 2008-02-01
Hi.

I have problem with ParameterDirection.InputOutput.

I'm still in problem when passing imput value to InputOutput parameter. When i look on SQL I see that there is alway NULL pased regardles to what I set to Value.

Code:
SqlC_GetActualVersion.Parameters("@version").Value = CDec(Version)
SqlC_GetActualVersion.Parameters("@version").Direction = ParameterDirection.InputOutput
SqlC_GetActualVersion.Connection.Open()
SqlC_GetActualVersion.ExecuteReader()
SqlC_GetActualVersion.Connection.Close()
Version = CType(SqlC_GetActualVersion.Parameters("@version").Value, String)

SQL command send in background:
declare @P1 numeric(8,4)
SET @P1=NULL
EXEC dbo.GetActualVersion @version=@P1 output


Return value is Ok.
0
Comment
Question by:patrikt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 10

Expert Comment

by:EBatista
ID: 12014845
you cannot access the reader value if you close the connection, and if you actually dont need the db cursor then use ExecuteNonQuery method instead:

SqlC_GetActualVersion.Connection.Open()
SqlC_GetActualVersion.ExecuteNonQuery()
SqlC_GetActualVersion.Connection.Close()
Version = CType(SqlC_GetActualVersion.Parameters("@version").Value, String)

regards
0
 
LVL 10

Expert Comment

by:EBatista
ID: 12015156
also ExecuteReader() method is for retrieve "records" from the database, it wont perform any insert or update, so if you are trying to write back changes or inserting rows to the db you have to use ExecuteNonQuery.
0
 
LVL 12

Author Comment

by:patrikt
ID: 12015157
Yes I know that. ExecuteReader is only "fosil" after my experimenting.

I'have found "way arround". Everything is working if ALL parameters are defined as InpurOutput and output in Sp. But why to do this? It looks like bug in SqlCommand.

Patrik
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 10

Expert Comment

by:EBatista
ID: 12015255
nope, no bugs, can u paste the whole code for the stored procedure
0
 
LVL 20

Expert Comment

by:ihenry
ID: 12017414
>> you cannot access the reader value if you close the connection
In addition to EBatista comment,
you can't as well retrieve the output parameters until close the datareader

Try this,
SqlC_GetActualVersion.Connection.Open()
SqlDataReader dr = SqlC_GetActualVersion.ExecuteReader()
dr.Close()
Version = CType(SqlC_GetActualVersion.Parameters("@version").Value, String)
SqlC_GetActualVersion.Connection.Close()
0
 
LVL 12

Author Comment

by:patrikt
ID: 12031223
There is no problem with reading parameters. There is problem with passing paramaters.
I investigatet this and there is my result:
1) Problem is only with SQLCommand. OLEDBCommand works well.
2) Problem is only when stored procedure has some but not all paramaters as output.
3) If 1 and 2 is true and I assign value to output parameter it is set to null when calling stored procedure regardles I set it as InputOutput.

Workaround is to set all parametere in stored procedure as output. Then it works OK. But it is still bug.

Any comments?
0
 
LVL 5

Accepted Solution

by:
ajitanand earned 500 total points
ID: 12109537
hello,

The correct order for setting parameters is:
Create a SQLParameter Object
Assign the parameter direction and Set the value

Then add to the parameters collection of the Command, and then execute.

rgds,
Ajit Anand
0
 
LVL 12

Author Comment

by:patrikt
ID: 12367231
This question is not answered. I went arround the problem and have no time to investigate the source of errors.

Please give some points to Experts participating, but don't PAQ this question.

Patrik
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MailAddress in vb 4 36
Add a Condition in ASP Repeater 6 45
Problem to Office 1 40
Asp.Net Session Question 2 33
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question