Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

xml string, Linq and varbinary(max)

Posted on 2010-08-30
11
Medium Priority
?
1,499 Views
Last Modified: 2012-05-10
Hi

using vs2010 asp.net, vb.bet

I have  a string containing an xml document that I need to store in a sql server varbinary(max) column.

How do you:
a) Store the string using linq to sql
b) retrieve and load the string into an xmldocument object.

Thanks in advance

Wing

0
Comment
Question by:WingYip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 33558659
Insert, Update, and Delete Operations (LINQ to SQL)
http://msdn.microsoft.com/en-us/library/bb386931.aspx

LINQ to SQL (Part 4 - Updating our Database)
http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx
0
 
LVL 1

Author Comment

by:WingYip
ID: 33558685
This stuff I know.  The issue is the varbinary datatype and how to store and retrieve.
Thanks
Wing
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33559118
it doesn't matter if the datatype is varbinary or varchar. you will get what you have stored in the same format. one thing is changed. varchar is not case sensitive but varbinary is case sensitive.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:WingYip
ID: 33559328
I've answered my own question now.

I cant just put a string into a varbinary datatype, it needs to be converted to a byte array first and then inserted as you would normally insert linq data.

The question was about the whole operation of saving a string into a varbinary datatype - nobody seemed to latch on to that - thanks for replies anyway.

Wing

Wing.
0
 
LVL 9

Accepted Solution

by:
puru1981 earned 1500 total points
ID: 33559475
you don't need to convert the string data to byte array before saving. it is tarnsparent from user.

i am giving you a sample

just create a table with two columns id int and data varbinary(50)

now use a insert command to insert data into the table

insert into tablename values(1,'junk data')
insert into tablename values(2,'junk data2')

now use a select query

select * from tablename

it will show the data inserted above.
0
 
LVL 1

Author Comment

by:WingYip
ID: 33559520
I've done it like this.  Is it unneseary?  What should I have done?

   'Store xml in db
        Dim xo As New bb_xml_order 'linq table
        xo.OrderHeaderId = ord.OrderHeaderId
        Dim enc As System.Text.Encoding = System.Text.Encoding.UTF8
        Dim barray As Byte() = enc.GetBytes(sXmlOrder)
        '''''''''Dim sRetrieve As String = enc.GetString(barray)  
        xo.xmlOrder = barray
        xo.filename = String.Format("{0}.xml", ord.GetXmlFileName)
        db.bb_xml_orders.InsertOnSubmit(xo)
        db.SubmitChanges()
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33559606
there is no need to convert it in binary until you don't want to be unreadable data from the sql query.

it is an overhead of making as bytestream and re arranging to string.
0
 
LVL 1

Author Comment

by:WingYip
ID: 33559647
The overhead is a non issue in this case.
The string will not be queried, just retrieved.  If stored as varchar, I understand there are encoding difficulties as varchar is utf-16 and the xml string is utf-8.

Wing
0
 
LVL 9

Expert Comment

by:puru1981
ID: 33559689
then what you have done is correct.
0
 
LVL 1

Author Comment

by:WingYip
ID: 33559696
thanks for the concern.

You can have the points
0
 
LVL 1

Author Closing Comment

by:WingYip
ID: 33559733
My solution is the correct one but grateful for help of puru1981 so awarding points to him
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question