473,385 Members | 1,753 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.

Parameter Direction Output

I have an SQL Stored Procedure that is outputting (using scope_indentity) the PersonID after a record is inserted into the table. I need this outputted value to be returned to my application. I have tried the following but I am getting errors..."Non-invocable member 'System.Data.SqlClient.SqlCommand.Parameters' cannot be used like a method." on the line "cmd.Parameters("@PersonID").Direction = ParameterDirection.Output;"
Expand|Select|Wrap|Line Numbers
  1.     public long InsertPerson()
  2.     {
  3.         SqlConnection conn = null;
  4.         SqlDataReader rdr = null;
  5.  
  6.         long lngPersonID = 0;
  7.  
  8.         try
  9.         {
  10.             conn = new SqlConnection("Server=Global2;DataBase=PictureCapture;Integrated Security=True");
  11.             conn.Open();
  12.  
  13.             SqlCommand cmd = new SqlCommand("InsertPerson", conn);
  14.             cmd.CommandType = CommandType.StoredProcedure;
  15.             cmd.Parameters.Add(new SqlParameter("@practicecode", this.practicecode));
  16.             cmd.Parameters.Add(new SqlParameter("@mrn", this.mrn));
  17.             cmd.Parameters.Add(new SqlParameter("@fname", this.fname));
  18.             cmd.Parameters.Add(new SqlParameter("@lname", this.lname));
  19.             cmd.Parameters.Add(new SqlParameter("@dob", this.dob));
  20.             cmd.Parameters.Add(new SqlParameter("@ssn", this.ssn));
  21.             cmd.Parameters.Add(new SqlParameter("@PersonID", 0));
  22.             cmd.Parameters("@PersonID").Direction = ParameterDirection.Output;
  23.  
  24.             rdr = cmd.ExecuteScalar();
  25.             lngPersonID = Convert.ToInt32(cmd.Parameters("@PersonID").Value);
  26.  
  27.         }
  28.         finally
  29.         {
  30.             if (conn != null)
  31.             {
  32.                 conn.Close();
  33.             }
  34.             if (rdr != null)
  35.             {
  36.                 rdr.Close();
  37.             }
  38.         }
  39.         return lngPersonID;
  40.     }
Oct 8 '09 #1
4 25973
Plater
7,872 Expert 4TB
Parameters is an array, not a function.
This is C#, use the array brackets, not the function brackets
cmd.Parameters["@PersonID"].Direction = ParameterDirection.Output;
Oct 8 '09 #2
Thanks, that solved that issue. I guess I am having a hard time letting go of the VB.NET I am used to!

But now I am getting an error on the line...
rdr = cmd.ExecuteScalar();
"Cannot implicitly convert type 'object' to 'System.Data.SqlClient.SqlDataReader'. An explicit conversion exists (are you missing a cast?)"
Oct 8 '09 #3
Plater
7,872 Expert 4TB
Then cast it :-)

sdr= (SqlDataReader)cmd.ExecuteScalar();
Oct 8 '09 #4
Thanks again Plater!
Oct 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Miguel Pardo | last post by:
I have an stored procedure which has an OUTPUT parameter, how can i get it, it has to be through a DataReader or something like that???? or when i call it??? can you give me an example??? or...
3
by: jw56578 | last post by:
I know that you can retrieve whether a parameter is for output buy way of the "isoutparam" field, but is there anything that tells you whether a parameter is input/output? thanks
0
by: Davide | last post by:
Hi We have a stored procedure for inserting data into a table and another for Updating that table. For the Insert SP we use a LastModifiedDateTime output parameter and for the Update SP we...
1
by: Vickey Nelson | last post by:
I am calling a stored procedure which returns the result set and output parameter. My code look like this.. Dim MyReader As SqlDataReader = myCmd.ExecuteReader() If Not...
10
by: Juan Sutton | last post by:
I'm building a web service and trying to get an output similar to this: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>...
4
by: Mr Not So Know It All | last post by:
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE . @in_rc varchar(8) @out_eList...
3
by: michelle | last post by:
I am trying to get an output value from a stored procedure using sqlDataSource in asp.net 2.0. But I only get a null value for the output. Can someone please help? The sqlDataSource: ...
1
by: John Mason | last post by:
Hi, I'm new to ASP.NET 2.0 and I am trying to get more information on the size property within the parameter tag of the SQLdatasource control. I have this code as an example... <asp:Parameter...
5
by: Trevisc | last post by:
Happy Thursday Everyone, I am trying to create a parameter that is one long varchar but that will be used in a SQL statement IN function: //string queryString = GetCurrentTitles(); //Below is...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.