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

Retrieving SqlCommand parameter values

Hi All

Trying to retrieve the value of the Sqlcommand' parameter as integer.
Here is how I declare it:
SqlParameter paramId = command.Parameters.Add("@id", SqlDbType.Int);
paramId.Direction = ParameterDirection.InputOutput;
paramId.Value = id;

......

The only method of the SqlParameter available is ToString() so I have
to retrieve it in the following ugly way:

id = Int64.Parse( "0" + paramId.Value.ToString() );

Anyone knows of a prettier way to do it?
Thanks very much!!!
Nov 16 '05 #1
2 5124
Dmitri,

The Value property is of type object. However, that doesn't mean that
it is an object that is stored. Since every type derives from object, it is
the only type the property can expose which will cover every possible value
returned.

In order to access your property, cast the result of the Value property
to int and then you should be able to access it normally.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dmitri Khanine" <kh*****@hotmail.com> wrote in message
news:d4**************************@posting.google.c om...
Hi All

Trying to retrieve the value of the Sqlcommand' parameter as integer.
Here is how I declare it:
SqlParameter paramId = command.Parameters.Add("@id", SqlDbType.Int);
paramId.Direction = ParameterDirection.InputOutput;
paramId.Value = id;

.....

The only method of the SqlParameter available is ToString() so I have
to retrieve it in the following ugly way:

id = Int64.Parse( "0" + paramId.Value.ToString() );

Anyone knows of a prettier way to do it?
Thanks very much!!!

Nov 16 '05 #2
Dmitri Khanine <kh*****@hotmail.com> wrote:
Trying to retrieve the value of the Sqlcommand' parameter as integer.
Here is how I declare it:

SqlParameter paramId = command.Parameters.Add("@id", SqlDbType.Int);
paramId.Direction = ParameterDirection.InputOutput;
paramId.Value = id;

.....

The only method of the SqlParameter available is ToString() so I have
to retrieve it in the following ugly way:

id = Int64.Parse( "0" + paramId.Value.ToString() );

Anyone knows of a prettier way to do it?


First check whether or not it's null (DBNull.Value) and otherwise, cast
it to int:

if (paramId.Value != DBNull.Value)
{
int id = (int) paramId.Value;
...
}

Alternatively:

if (paramId.Value is int)
{
int id = (int) paramId.Value;
...
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Justin | last post by:
I have created a dataset with two tables and an insert command, I need to be able to retreive the Key Identity after inserting into table "A" for use in table "B". Should I use ExecuteScalar()...
2
by: Patrick Olurotimi Ige | last post by:
I converted the code below from VB.NET to C# cos i have to add it to a C# application!! But i'm getting the error:- System.Data.SqlClient.SqlCommand.Parameters' denotes a 'property' where a...
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: Susanne Klemm | last post by:
Hello! I use a procedure to insert a new row into a table with an identity column. The procedure has an output parameter which gives me the inserted identity value. This worked well for a long...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
5
by: Sanjay Pais | last post by:
I have a table with over 1.3 million rows. I am retrieving only 20 at a time using the with - over clauses In query analyser, the data is retrieved in under a second. When retrieving using the...
19
by: shamaila | last post by:
i want to retrieve primary key of parent table and then send this key to child table,as they have one-one relationship i've written code string id = "SELECT MAX(c_id) FROM call_history"; ...
2
by: jenniamia | last post by:
I need to make the string "myFile" into a byte and then put it in the database as a file/image, where later it needs to be pulled out and back into a string from the byte. I'm really having trouble...
2
by: TheSteph | last post by:
Hi I have a SQLCommand that do updates on a table. I have a loop where I set the parameters then I call ExecuteNonQuery. For . { . Set the SQLCommand's Params Values;
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.