Monday 15 June 2015

vb.net - How to convert an string to a Char(20) sql datatype -


I try to insert a string into a char (20) column in my SQL server database I am doing .

I set the string to be equal to one value and then add it to a parameter

  thisstring = "1914" cmd.Parameters.AddWithValue (" @ Code ", this string)   

Although every time I try, it ends up looking like this in the database

 picture

I like this like 1913, 000000, 000001 .

This string = thisstring.PadLeft (20, "")

When I try to string string with this string

  > 

or

  thisstring = "" & Amp; The string   

I am getting

string or binary data will be minimized

even if the field

>

I'm not sure at all, but I think the problem is in AddWithValue.
While convenient, this method does not allow specifying the exact datatype to pass the database engine nor the size of the parameter. It always passes a nvarchar parameter for the C #Unicode string.

I think the standard parameter

  dim p = new SqlParameter ("@ code", SqlDbType.Char, 20) p.Value = thisstring.PadLeft (20 , "")   



No comments:

Post a Comment