473,791 Members | 2,899 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parameter Direction Output

13 New Member
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.Sq lClient.SqlComm and.Parameters' cannot be used like a method." on the line "cmd.Parameters ("@PersonID").D irection = ParameterDirect ion.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 26004
Plater
7,872 Recognized Expert Expert
Parameters is an array, not a function.
This is C#, use the array brackets, not the function brackets
cmd.Parameters["@PersonID"].Direction = ParameterDirect ion.Output;
Oct 8 '09 #2
klharding
13 New Member
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.ExecuteScal ar();
"Cannot implicitly convert type 'object' to 'System.Data.Sq lClient.SqlData Reader'. An explicit conversion exists (are you missing a cast?)"
Oct 8 '09 #3
Plater
7,872 Recognized Expert Expert
Then cast it :-)

sdr= (SqlDataReader) cmd.ExecuteScal ar();
Oct 8 '09 #4
klharding
13 New Member
Thanks again Plater!
Oct 8 '09 #5

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

Similar topics

1
323
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 how??? Any help will be welcome, thanX!!!!
3
1752
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
1141
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 use the InputOutput parameter direction. When we execute the query the following line works for
1
1065
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 Convert.IsDBNull(myCmd.Parameters("@TotalCount").Value) Then iTARCount = CType(myCmd.Parameters("@TotalCount ").Value, String)
10
34192
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> <Add2Response> <Add2Result>3</Add2Result> <sum>3</sum> </Add2Response>
4
50417
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 varchar(7) output AS select @out_eList = ecuid from _organization where rccode = @in_rc GO
3
11285
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: <asp:SqlDataSource ID="DataSource1" runat="server" ConnectionString="<%$ ConnectionStrings: ConnectionString1 %>" SelectCommand="UserLkp" SelectCommandType="StoredProcedure"
1
3878
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 Type="String" Name="NewID" Direction="Output" Size="4"> Does Size="4" represent 4 characters in length? In the case of an IDENTITY integer being returned after an INSERT, does having size = "4"
5
5308
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 for Test string queryString = "45322,32222,33344,55555"; dataset catalogDS = new dataset();
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5430
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.