I have a table in which there is one column named:
'eZip' (varbinary(5), null).
Now I am adding value from a web form like this:
cmd.Parameters.Add("@eZip", SqlDbType.VarBinary).Value = BitConverter.GetBytes(int.Parse(txtZip.Text.ToString()));
Its working but instead of putting a valid zip code, it is inserting this into my column:
<Binary data>
What I am doing wrong here?
charorvarchar. Converting a zip code to anintis a bad idea in the first place, and then converting theintto binary is another bad idea.charorvarchar. If you're only going to be handling US zip codes,char(5)(orchar(10)if you want to handle the hyphen+4) would be the best choice.