Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. XML into byte ??

XML into byte ??

Scheduled Pinned Locked Moved Visual Basic
databasesql-serversysadminxmlhelp
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XGaMeS
    wrote on last edited by
    #1

    I want to store xml file in a ntext datatype in sql server 2000, someone have any idea how to do this ? By the way it's an XMLDocument who need to be stored and they are no more than 3-4k. I have no idea on how to do that.. please help me !:eek: I am a somehow a newbie

    C C 2 Replies Last reply
    0
    • X XGaMeS

      I want to store xml file in a ntext datatype in sql server 2000, someone have any idea how to do this ? By the way it's an XMLDocument who need to be stored and they are no more than 3-4k. I have no idea on how to do that.. please help me !:eek: I am a somehow a newbie

      C Offline
      C Offline
      Chris Quick
      wrote on last edited by
      #2

      You could convert the document into a string and then store it in the database. May not be the most compact way of storing it, however.

      1 Reply Last reply
      0
      • X XGaMeS

        I want to store xml file in a ntext datatype in sql server 2000, someone have any idea how to do this ? By the way it's an XMLDocument who need to be stored and they are no more than 3-4k. I have no idea on how to do that.. please help me !:eek: I am a somehow a newbie

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        XGaMeS wrote: I want to store xml file in a ntext datatype in sql server 2000 Erm... what is XML, if it's not text ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        X 1 Reply Last reply
        0
        • C Christian Graus

          XGaMeS wrote: I want to store xml file in a ntext datatype in sql server 2000 Erm... what is XML, if it's not text ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

          X Offline
          X Offline
          XGaMeS
          wrote on last edited by
          #4

          And any clues on how to conevert it and pass it as a parameters ? I am...

          C D 2 Replies Last reply
          0
          • X XGaMeS

            And any clues on how to conevert it and pass it as a parameters ? I am...

            C Offline
            C Offline
            Chris Quick
            wrote on last edited by
            #5

            Okay, here's a senario that may help. Create your stored procedure to handle actually commiting the data to the database

            CREATE PROCEDURE InsertXMLData
            {
            @XMLData ntext
            }

            AS
            INSERT INTO MyDemoTable (XMLData) VALUES (@XMLData);
            GO

            To use this procedure do the following:

            Private Sub InsertXML(ByVal XMLData as XMLDocument)
                 ' create a sqlconnection 
                 Dim SQLCon as New SQLConnection("server=...")
                 
                 ' create a sql command
                 Dim SQLCon as New SQLCommand("InsertXMLData", SQLCon)
                 
                 ' Set the command type and add parameters
                 SQLCon.CommandType = CommandType.StoredProcedure
                 SQLCon.Parameters.Add("@XMLData", XMLData.OuterXML.ToString)
                   
                 ' Variable to store records added.
                 Dim RecordsAdded as Integer      
                   
                 ' Execute a non-query
                 Try
                    SQLCon.Open
                    RecordsAdded = SQLCmd.ExecuteNonQuery
                 Catch sqlex as SQLException
                    RecordsAdded = -1
                 Catch ex as Exception
                    RecordsAdded = -1
                 Finally
                    SQLCon.Close
                 End Try
            End Sub
            

            You will want to make sure to research more about the System.Data.SQLClient namespace for more information on using parameters with SQL Commands. Hope this is useful!

            1 Reply Last reply
            0
            • X XGaMeS

              And any clues on how to conevert it and pass it as a parameters ? I am...

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              There's nothing to convert. You just open the file and read it into a string.

              Dim sr As StreamReader = New StreamReader("C:\\myPath\\TestFile.xml")
              Dim content As String
              content = sr.ReadToEnd()
              sr.Close()
              

              Then you just pass the string to your SQLCommand as you would any other SQLParameter. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              C 1 Reply Last reply
              0
              • D Dave Kreskowiak

                There's nothing to convert. You just open the file and read it into a string.

                Dim sr As StreamReader = New StreamReader("C:\\myPath\\TestFile.xml")
                Dim content As String
                content = sr.ReadToEnd()
                sr.Close()
                

                Then you just pass the string to your SQLCommand as you would any other SQLParameter. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                *sigh* Thank you. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups