INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Bug in cmd.Parameters statement and byte?

Bug in cmd.Parameters statement and byte?

(OP)
I have some code I am converting from 2008 to 2013 and found a situation where the code is handled differently.

I have a statement:

cmd.Parameters.Add(new SqlParameter("@NameType", (byte)1))

This works correctly in 2008 and 2013 and puts a "1" in the value field

If I do:

cmd.Parameters.Add(new SqlParameter("@NameType", (byte)0))

it puts a "0" in the value of the parameter in VS2008 but in VS2013, it puts a null.

I am trying to find out if this is an issue only with cmd.Parameters.Add or is it with areas?

I did do:

(byte)dr["NameType"])

And if the value is 0 it will return a 0.

Since this is a fairly large project I need to find out if there are other areas where this could be an issue.

Thanks,

Tom

RE: Bug in cmd.Parameters statement and byte?

Tom

Have you tried,

dim mycommand as new sqlcommand
dim shipmentid as string = ("12345")


with mycommand

.Parameters.Add("myparam", SqlDbType.Bit, 1, shipmentid) 'Note you dont need the "@" here in myparam.

end with

(parameter name as string, SqlDbType as system,data.SqlDbType, size as integer, source column as string)



I use this construct in VS 2012 without any problems

RE: Bug in cmd.Parameters statement and byte?

(OP)
The problem is not that my format doesn't work (it does for (byte)1 and anything else).

It is just that (byte)0 should have passed 0 correctly and it doesn't seem to (or it messes up in the Add method).

I am just trying to find out if this is an anomaly and it is the only place where it is an error.

Thanks,

Tom

RE: Bug in cmd.Parameters statement and byte?

Ok Tom


Have you iterated through your parms after values etc. have been assigned to see what's actually in them.

For X As Int32 = 0 To cmd.Parameters.Count - 1
Response.Write(cmd.Parameters(X).ParameterName & "Name: " & cmd.Parameters(X).Value & " Size is. " & cmd.Parameters(X).Size & "<br />")
Next

RE: Bug in cmd.Parameters statement and byte?

(OP)
Yes.

The value actually is null. It gave me an error since it was trying to move the null into tinyint.

When I run it in VS 2008, the value is a 0.

RE: Bug in cmd.Parameters statement and byte?

Do you need to use a type of byte? Are the values only going to be 0 or 1? If so, then use a bit type.

RE: Bug in cmd.Parameters statement and byte?

(OP)
You miss my point.

It isn't working correctly. I know how to fix it.

I am trying to find out if this is the only bug. It should be setting the tinyint to a 0 and isn't.

Either 2008 or 2013 is wrong.

If I pass a (byte)0 it should be 0. (byte)1 is equal to 1.

RE: Bug in cmd.Parameters statement and byte?

I don't know the answer to that. You will have to search or look on the MS website to see if there is any information regarding it.
In the meantime, just do the fix to get your code working.

RE: Bug in cmd.Parameters statement and byte?

When I test this using VB, it wouldn't even let me cast an integer to a byte, it would only accept strings. It could just be something relevant to C#.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close