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;" - public long InsertPerson()
-
{
-
SqlConnection conn = null;
-
SqlDataReader rdr = null;
-
-
long lngPersonID = 0;
-
-
try
-
{
-
conn = new SqlConnection("Server=Global2;DataBase=PictureCapture;Integrated Security=True");
-
conn.Open();
-
-
SqlCommand cmd = new SqlCommand("InsertPerson", conn);
-
cmd.CommandType = CommandType.StoredProcedure;
-
cmd.Parameters.Add(new SqlParameter("@practicecode", this.practicecode));
-
cmd.Parameters.Add(new SqlParameter("@mrn", this.mrn));
-
cmd.Parameters.Add(new SqlParameter("@fname", this.fname));
-
cmd.Parameters.Add(new SqlParameter("@lname", this.lname));
-
cmd.Parameters.Add(new SqlParameter("@dob", this.dob));
-
cmd.Parameters.Add(new SqlParameter("@ssn", this.ssn));
-
cmd.Parameters.Add(new SqlParameter("@PersonID", 0));
-
cmd.Parameters("@PersonID").Direction = ParameterDirection.Output;
-
-
rdr = cmd.ExecuteScalar();
-
lngPersonID = Convert.ToInt32(cmd.Parameters("@PersonID").Value);
-
-
}
-
finally
-
{
-
if (conn != null)
-
{
-
conn.Close();
-
}
-
if (rdr != null)
-
{
-
rdr.Close();
-
}
-
}
-
return lngPersonID;
-
}
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;
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?)"
Plater 7,872
Recognized Expert Expert
Then cast it :-)
sdr= (SqlDataReader) cmd.ExecuteScal ar();
Sign in to post your reply or Sign up for a free account.
Similar topics |
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!!!!
|
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
|
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
|
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)
|
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>
| |
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
|
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"
|
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"
|
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();
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |