Hi all,
When I call a stored procedure, one of the output parameter returns a
sqldbtype.integ er but when assigned to a C# int field/property I get this
error:
int myfield;
// say, parms[0] is the sql integer data
myfield = parms[0]; // creates the error.
Error 1 Cannot implicitly convert type 'System.Data.Sq lClient.SqlPara meter'
to 'int'
also, parms[0] is a nullable column in the database. 3 14455
Amil wrote: Hi all, When I call a stored procedure, one of the output parameter returns a sqldbtype.integ er but when assigned to a C# int field/property I get this error:
int myfield; // say, parms[0] is the sql integer data myfield = parms[0]; // creates the error. Error 1 Cannot implicitly convert type 'System.Data.Sq lClient.SqlPara meter' to 'int'
also, parms[0] is a nullable column in the database.
Im not sure if you have to use the .Value property of the parameter but
I think you do, so:
if(parms[0].Value != dbnull) //Whatever dbnull is called
{
myfield = (int)parms[0].Value;
}
JB
cool. i think adding the .Value made it work; thank for the null checking too.
"John B" wrote: Amil wrote: Hi all, When I call a stored procedure, one of the output parameter returns a sqldbtype.integ er but when assigned to a C# int field/property I get this error:
int myfield; // say, parms[0] is the sql integer data myfield = parms[0]; // creates the error. Error 1 Cannot implicitly convert type 'System.Data.Sq lClient.SqlPara meter' to 'int'
also, parms[0] is a nullable column in the database.
Im not sure if you have to use the .Value property of the parameter but I think you do, so:
if(parms[0].Value != dbnull) //Whatever dbnull is called { myfield = (int)parms[0].Value; }
JB
hi,
parms[0] is an instance of SqlParameter , of course you cannot cast it to
an int.
do this:
int i = Convert.ToInt32 ( parms[0].Value );
or
int i = (int) parms[0].Value ;
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Amil" <Am**@discussio ns.microsoft.co m> wrote in message
news:22******** *************** ***********@mic rosoft.com... Hi all, When I call a stored procedure, one of the output parameter returns a sqldbtype.integ er but when assigned to a C# int field/property I get this error:
int myfield; // say, parms[0] is the sql integer data myfield = parms[0]; // creates the error. Error 1 Cannot implicitly convert type 'System.Data.Sq lClient.SqlPara meter' to 'int'
also, parms[0] is a nullable column in the database. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Anton |
last post by:
I have a table of zip codes, some with Canadian zips. I'd like to take
a zip code and search for nearby zips. For example:
Dim theZip As Integer = textbox1.text
....Parameter.Add(@ziplow, SqlDbType.Int, 5).Value = (theZip - 10)
....Parameter.Add(@ziphigh, SqlDbType.Int, 5).Value = (theZip + 10)
SELECT * from ZIPCODES where Cast(zip_code as Integer) BETWEEN @lowzip
AND @highzip
|
by: Mac |
last post by:
I have imported some data to sql2k from my old system. Somehow, it imported
invoice amount to char type.
I just created another column called invamt2 type NUMERIC so I can copy or
convert content of invamt which is type CHAR. There are about 50,000
records.
How can I convert/cast from char type to numeric type ?
Thanks
|
by: studen77 |
last post by:
Thanks to anyone in advance who can help :)
Ok, I know this is a far stretch, but what I'm trying to do is to cast a
System.object as one of the SqlDbType enumerations (SqlDbType.Int,
-.NVarchar, etc.) Is this anyway possible? Through inheritance, or anything?
|
by: Daniel Groh |
last post by:
I'm facing this error:
Error Message:Specified cast is not valid.
this line:
char chrTipoPessoa = (char)sqlCmd.ExecuteScalar();
It should returns the letter "F" or "J"!
but with (string) it works normal...I already checked and there's no space!
Why I'm getting this error when I try to cast as char ?
|
by: Ant |
last post by:
Hi,
I'm trying to find out the benefits of one type of conversion method over
another.
When would it be best to use casting over Converting e.g.
(int)stringValue as opposed to
Convert.ToInt(stringValue)
| |
by: Narshe |
last post by:
If I use this simple code
SqlParameter param = new SqlParameter( "@param", SqlDbType.DateTime );
param.Value = System.DateTime.Now;
param.Value is "11/2/2005" rather than "11/2/2005 10:42:15 AM"
How do I get it so the sql value is the same as the C# value, and not
truncated?
|
by: Hifni Shahzard |
last post by:
Hi,
I got a stored procedure, where it returns a value. But if I execute it. It
gives an error as "Invalid cast from System.Int32 to System.Byte.". To make
clear how do I execute this, below I'm specifiying my code:
The Code used in Visual Studio:
Function GetRank(ByVal ID As Integer, ByVal Comp As String, ByVal Sec As
String, ByVal iDate As Date) As String
'Dim Ret As Integer
|
by: bborowin |
last post by:
Hi there,
Given a collection of SqlDbType enums (eg, {BigInt, VarChar, Bit}), I
need to convert it to a collection of corresponding C# Types (here,
{long, string, bool}).
The contents of the source collection is not known ahead of time; it
could be any valid combination of enums in the SqlDbType enumeration.
Short of writing an explicit switch statement for all elements in the
|
by: Rene Sluiter |
last post by:
Guys, I've been trying to convert/cast a nvarchar value like
719.928,000000 to a number but I keep getting a conversion failed error.
I think it's the thousandsseparator that's giving me troubles but I have no idea how to tell sql that the string is a number formated a special way like I can do with date styles.
Can anyone help me? Do I need to remove the thousandsseparator before the convert/cast? And if so, how should I do that?
...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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: 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: 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...
| |