VarBinary ?

W

WJ

I have an MS/SQL Table with a field defined as "VarBinary(128)" and an
Asp.Net application form with a TextBox that will accept user input as
LastName.

1. I can write the TextBox (LastName) to the MS/SQL table as
convert(VarBinary(128),@LastName).
2. I can read back into my DataSet as "VarBinary".

3. How do I convert the DataSet field from VarBinary back to the
TextBox/LastName field on the Asp.Net form ?

Thanks,

John
 
C

Cowboy \(Gregory A. Beamer\)

I am not sure why anyone would desire to store a textbox in a database. The
norm is to store only the text contained in the textbox in the database, as
that is the data that is important. If you actually want to store an object
like a textbox, I would look at a BinaryWriter, but to get a textbox on a
web page, you will have to write something that translates the raw bytes to
HTML, which is a rather large task to conquer for diminishing returns.

Perhaps there is a reason I am not seeing. If so, please explain the thought
process behind the form and I may have more input. Hope this helps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
W

WJ

I think I did not explain very well. It is the data from the TextBox control
on the Asp.Net form that is to be stored on a database table, not the object
"TextBox" itself. Here is the example:

1. My table is "Create Table myTable(LastName VarBinary(128))"
2. My Insert command is "Insert MyTable
values(Convert(VarBinary(128),@LastName))" - This always works as expected
3. My DataSet command is "Select LastName from MyTable order by LastName) -
This always works as expected
4. Now my Asp.Net form has the DataSet returned with LastName value in
VarBinary data. How can I convert the data in VarBinary back to my
LastName.Text on my Asp.Net form ?

Please note: I can convert the VarBinary data from within the SQL/Server but
prefer not to do it. I would like the VarBinary format to travel in its
DataSet all the way back to the Asp.Net form.

John
 
C

Cowboy \(Gregory A. Beamer\)

In an ASP.NET textbox, you store text. Bearing this in mind, a varchar is a
much better data type in a database than varbinary, as you are storing text.
If you need text from different languages, consider nvarchar instead. There
is no reason to use a varbinary unless you are also storing binary bits.

From what you have described, I do not see a reason to have this as
varbinary, as you are not storing binary information. If you leave the field
as varchar, there is no reason to convert. Am I still missing something?

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
 
W

WJ

Cowboy (Gregory A. Beamer) said:
In an ASP.NET textbox, you store text. Bearing this in mind, a varchar is
a much better data type in a database than varbinary, as you are storing
text.

Yes. I agree, the same hold true to Password
If you need text from different languages, consider nvarchar instead.
There is no reason to use a varbinary unless you are also storing binary
bits.

From what you have described, I do not see a reason to have this as
varbinary, as you are not storing binary information. If you leave the
field as varchar, there is no reason to convert. Am I still missing
something?
Yes, you are missing my point: It is very simple: How to convert a VarBinary
to string ? The Convert method does not show VarBinary. However, SQL server
does this without difficulty. The same holds true: If I hand you a file with
VarBinary, how do you go about and convert it to a readable format using c#
?

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top