Hi,
I am trying to retrieve a value from database, based on that value I want to insert records into DB.Let’s say I am retrieving tsmid which serves as the output parameter in the stored procedure.
.net/C# code is -
public void getTSmid()
-
{
-
int tsid=0;
-
tsid = System.Convert.ToInt32(SqlHelper.ExecuteReader(SqlHelper.tConnectionString,
-
CommandType.StoredProcedure, "GetTSMID_SP",
-
new SqlParameter("@PID", this.PId),
-
new SqlParameter("@EN", this.En),
-
new SqlParameter("@ESG",this.Esg),
-
new SqlParameter("@TSMID", SqlDbType.Int, 4, ParameterDirection.Output, true, 5, 0, "TSMId", DataRowVersion.Current, tsid)));
-
TSM = tsid;
-
}
-
I have the DB connection classes in DLL and above code in BLL.
I am holding the output value into the integer tsid variable which is in the end assigned to TSM variable. I am getting the following error “Unable to cast object of type 'System.Data.Sq lClient.SqlData Reader' to type 'System.IConver tible'”
MY Q’: how to handle a output parameter in ASP.net?
Stored procedure looks like this: -
CREATE PROCEDURE [dbo].[GetTSMID_SP]
-
-
@EN Integer,
-
@PID Integer,
-
@ESG varchar(25),
-
@TSMID integer OUTPUT
-
AS
-
DECLARE @ TSMID int
-
DECLARE @total int
-
-
SELECT @total=Count(*) from tbl_Timer where EN =@EN and PID =@ PID and ESG =@ESG
-
if( @total = 0)
-
Begin
-
INSERT INTO tbl_Timer(EN, PID, ESG)
-
VALUES(@EN, @ PID, @ESG)
-
SELECT @ TSMID = @@Identity
-
end
-
else
-
begin
-
select @ TSMID=TSMID from tbl_Timer where EN =@ EN and PID =@PID and ESG =@ESG
-
end
-
1 3692 Plater 7,872
Recognized Expert Expert
Well I am not sure why you are trying to convert your DataReader to an int, but yes that is the wrong thing to do.
Assuming your SQL procedure is correct (not sure what it's doing, its very nested)
If you added the SqlParameter for your output value correctly. (What you have it a bit over zealous but will probably work)
All you need to do is call the Execute function and then get the value from the parameter:
tsid= (int)sc.Paramet ers["@TSMID"].Value;
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: MS |
last post by:
Here's my simple stored procedure:
ALTER PROCEDURE GetMemberIDByEmail
@Email EmailAddress,
@ID int OUTPUT
AS
SELECT @ID = ID FROM tbl_Member WHERE Email=@Email
RETURN
|
by: James Brett |
last post by:
Hi
I've got this function that executes a stored procedure. One of the
parameters is an output parameter but for some reason it always returns 0.
Any clues?
Cheers
James
|
by: James Radke |
last post by:
Hello,
I am looking for guidance on best practices to incorporate effective and complete error handling in an application written in VB.NET. If I have the following function in a class module (note that this class module represents the business layer of code NOT the gui layer):
Public Function Test(ByVal Parm1 As Integer, ByVal Parm2 As Integer) As SqlDataReader
' Declare the SQL data layer class
Dim oSQL As New...
|
by: Islamegy® |
last post by:
When i call stored procedure which have an output paramter, t'm unable to
get the value
How could i fix it??
here is the method....
----------------------------
userid = 0;
SqlParameter collection = new SqlParameter
{
new SqlParameter("@ID",DBNull.Value),
|
by: rockdale |
last post by:
Hi, All
How to get the output parameter's value when you use the SQLHelper
(Microsoft Data Access Block)?
When I try to access my ourput parm I got the following error.
System.NullReferenceException: Object reference not set to an instance
of an object.
I thought it is because there is a statement cmd.Parameters.Clear() in
| |
by: c676228 |
last post by:
Hi everyone,
I wrote a store procedure that fetch one row data in the database based on
the parameter value I entered. After I created the store procedure,
the store procedure code looks like this:
ALTER proc getProductCommScale @product As varchar(30), @TISCommRate As
Decimal(5,2) OUTPUT,
@BrokerCommRate As Decimal(5,2) OUTPUT, @Fee As Decimal(5,2) OUTPUT
As
if RTRIM(@product)='Imed'
Select @TISCommRate=TISComm,...
|
by: ashtek |
last post by:
Hi,
I have a generic function that executes a stored procedure & returns a
data table.
Code:
===
public static DataTable ExecuteStoredProcedure(string
strProc,SqlParameter paramArray)
{
SqlCommand command = new SqlCommand(strProc, connection);
command.CommandType = CommandType.StoredProcedure;
|
by: Igor |
last post by:
Hi
I have a drop down list on my page that lists some items returned from a
database. Each item has its GUID (or uniqueidentifier). I have to (in code
behind of the page) read this GUID, to hand it over to a query (stored
procedure) that takes the GUID and looks for some data in a specific table.
I don't know have to hand it to the query as GUID.
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
|
by: klharding |
last post by:
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;"
public long...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |