473,407 Members | 2,314 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,407 software developers and data experts.

Loading a char value from an SQL parameter - Crashing!

Hi:

Newby Question:

I have the following code in a class library that performs a query on an SQL
database and is returning a class that contains "locatestatus":

if (p_locatestatus.Value != System.DBNull.Value)
{ rtrec.locatestatus = (char)p_locatestatus.Value; };

rtrec.locatestatus is a char.

This compiles just fine however it causes an error and is trapped by my
try/catch everytime. There must be something that I need to do to convert a
char - all other types are converting just fine.

Any info on the steps I'm missing would be greatly appreciated!

Thanks,

Fred
Nov 17 '05 #1
4 1337
What exception does it generate?

Nov 17 '05 #2
Hi,

why don't you set a breakpoint in the if line and see the type of
p_locatestatus.Value, a quickwatch will do the trick.

Also what about using Convert.ToChar instead of the cast?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fred Nelson" <fr**@smartybird.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
Hi:

Newby Question:

I have the following code in a class library that performs a query on an
SQL
database and is returning a class that contains "locatestatus":

if (p_locatestatus.Value != System.DBNull.Value)
{ rtrec.locatestatus = (char)p_locatestatus.Value; };

rtrec.locatestatus is a char.

This compiles just fine however it causes an error and is trapped by my
try/catch everytime. There must be something that I need to do to convert
a
char - all other types are converting just fine.

Any info on the steps I'm missing would be greatly appreciated!

Thanks,

Fred

Nov 17 '05 #3
Hi Bruce:

Good question - I should have included this!

It generates: System.InvalidCastException - Specified cast it not valid.

Thanks,

Fred
"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
What exception does it generate?

Nov 17 '05 #4
Ignacio:

Even though the parameter is defined as being SqlDbType.Char it was showing
as a string at the breakpoint.

The Convert.ToChar solved the problem for me!

Thank you very much for your help!

Fred
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@tk2msftngp13.phx.gbl...
Hi,

why don't you set a breakpoint in the if line and see the type of
p_locatestatus.Value, a quickwatch will do the trick.

Also what about using Convert.ToChar instead of the cast?
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fred Nelson" <fr**@smartybird.com> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl...
Hi:

Newby Question:

I have the following code in a class library that performs a query on an
SQL
database and is returning a class that contains "locatestatus":

if (p_locatestatus.Value != System.DBNull.Value)
{ rtrec.locatestatus = (char)p_locatestatus.Value; };

rtrec.locatestatus is a char.

This compiles just fine however it causes an error and is trapped by my
try/catch everytime. There must be something that I need to do to convert a
char - all other types are converting just fine.

Any info on the steps I'm missing would be greatly appreciated!

Thanks,

Fred


Nov 17 '05 #5

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

Similar topics

9
by: ambar.shome | last post by:
Hi , Can anyone tell me when should I use char**. Does it have nay extra advantage over char*& ? "strtol" function takes char** as one of its parameters. But,cant understand why that is needed?...
5
by: jab3 | last post by:
(again :)) Hello everyone. I'll ask this even at risk of being accused of not researching adequately. My question (before longer reasoning) is: How does declaring (or defining, whatever) a...
14
by: mr_semantics | last post by:
I have been reading about the practise of casting values to unsigned char while using the <ctype.h> functions. For example, c = toupper ((unsigned char) c); Now I understand that the standard...
13
by: poison.summer | last post by:
For instance, I'd like to use unsigned char as an 8-bit integer. Can I use like unsigned char a=0; a++ Thanks a lot!
3
by: Arnold | last post by:
I am having problem loading the image from the database. It gives this error: "Invalid parameter used." This is my source code: Private abyt() As Byte Private fo As New OpenFileDialog Private sf...
3
by: Bri | last post by:
AC97 on WinXP, Image control on a Form and on a Report. I have followed the advice on the following MVPS page: http://www.mvps.org/access/api/api0038.htm This states that after changing the...
7
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each...
16
by: Virtual_X | last post by:
if we use char in a function parameter like that void st(char x) {cout << x;} and char* as a parameter in the same function instead of char x what would be different in my experiments i...
24
by: DomoChan | last post by:
the code below will compile in visual c++ 2003, but im not sure its valid. unsigned char myString = ""; after this line executes, all the bytes within myString are indeed set to '0's' but is...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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,...
0
isladogs
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...

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.