473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Read from xml file stored in a SQL database table’s field.

Hello all I am a beginner .Net programmer so please forgive my ignorance.

In brief, I am trying to read from xml file stored in a SQL database table’s
field.

This is what I used to create the table:
CREATE TABLE Document (
DocID int IDENTITY NOT NULL,
Description nvarchar(50) NOT NULL,
DocumentStore xml NOT NULL,
CONSTRAINT PK_Document PRIMARY KEY CLUSTERED
(
DocID ASC
)
)

This is what I used to insert my XML document into a SQL database table’s
field.
INSERT INTO Document (Description, DocumentStore)
VALUES('Bruce''s poem',
N'<?xml version="1.0" ?>
<Document Name="Poem">
<Author>Bruce</Author>
<Text>The cat/is flat.</Text>
</Document>')
This is my XML document’s contents.
<?xml version="1.0"?>
<Document Name="CRCPermission">
<ToolBars>
<Permission>
<PermissionName>Security Tool Bar</PermissionName>
<GrantAccess>True</GrantAccess>
</Permission>
<Permission>
<PermissionName>Employee Tool Bar</PermissionName>
<GrantAccess>True</GrantAccess>
</Permission>
<Permission>
<PermissionName>Case Find Tool Bar</PermissionName>
<GrantAccess>True</GrantAccess>
</Permission>
<Permission>
<PermissionName>Case Look Up Tool Bar</PermissionName>
<GrantAccess>True</GrantAccess>
</Permission>
<Permission>
<PermissionName>Allegations Tool Bar</PermissionName>
<GrantAccess>False</GrantAccess>
</Permission>
<Permission>
<PermissionName>Subjects Tool Bar</PermissionName>
<GrantAccess>True</GrantAccess>
</Permission>
<Permission>
<PermissionName>Hiring Authority Tool Bar</PermissionName>
<GrantAccess>False</GrantAccess>
</Permission>
</ToolBars>
</Document>

This is my code I use to display my XML document into my form’s list view
control.
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient
Imports System.Xml
Imports System.Xml.XPath
Imports System.Data.SqlTypes
Imports System.Configuration
Imports Microsoft.Data.SqlXml
Imports System.Data.OleDb

Public Class Form1
Dim WithEvents xmldoc2 As Xml.XmlDataDocument ' "MAKE GLOBAL"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim investigationsinfo As New SqlDataAdapter("select TOP 1
DocumentStore from Document FOR XML AUTO, TYPE", SqlConnection1)
Dim ds As DataSet
SqlConnection1.Open()
ds = New DataSet()
'filling the dataset
investigationsinfo.Fill(ds, "Document")
Dim InvestDataSet As XmlDataDocument
InvestDataSet = New XmlDataDocument(ds)
'I put this one in to see if it had a different result
Dim root As XmlNode = InvestDataSet.DocumentElement
Dim elemList1 As XmlNodeList
Dim elemList2 As XmlNodeList
Dim Employee As XmlNode
Dim Child As XmlNode
Dim NewItem As Boolean
Dim ict As Integer
Dim Lv
'I want either one to work
elemList2 = root.SelectNodes("descendant::ToolBars/Permission")
elemList1 = InvestDataSet.GetElementsByTagName("ToolBars/Permission")
For Each Employee In elemList1
' Use the Text property of each node
' to write the listview
NewItem = True
ict = 0
For Each Child In Employee.ChildNodes
If NewItem Then
lv = ListView1.Items.Add(Child.InnerText)
NewItem = False
Else
ict = ict + 1
lv.SubItems(ict) = _
Child.InnerText
End If
Next
Next
SqlConnection1.Close()
End Sub
End Class

I am using Microsoft Visual Basic 2005 and SQL Server 2005:
Microsoft SQL Server Management Studio 9.00.1399.00
Microsoft Analysis Services Client Tools 2005.090.1399.00
Microsoft Data Access Components (MDAC) 2000.085.1117.00
(xpsp_sp2_rtm.040803-2158)
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 6.0.2900.2180
Microsoft .NET Framework 2.0.50727.42
Operating System 5.1.2600

This code above only returns some value to the variable when I reference
“Document”.
elemList2 = root.SelectNodes("descendant::Document")
elemList1 = InvestDataSet.GetElementsByTagName("Document")

Help Please

--
thanks for your help...
Sep 17 '06 #1
0 3463

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ding feng | last post by:
I have got formatted files. All of these file takes this form: obj1 method1 obj2 string1 obj3 string2 argument. Of course, each file can have maximum fields as shown above, or minimun fields...
0
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id of the picture (an integer) and one (column named picture) is a field of type OLE Object which...
3
by: Karen Grube | last post by:
Hi! Each week, we receive a two-page PDF file from UPS along with a separate flat file (a CSV) The PDF file contains the overview of our weekly invoice and the CSV contains the details of each...
1
by: Alex | last post by:
Hi all, Just been dabbling with java stored procedures and I'm having problems replacing System: db2 8.1.4 on RH 7.1 linux system 1). Look at java jdbc samples as supplied with db2 and run...
3
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id if the picture (an integer) and one (column named picture) is a field of type OLE Object which...
8
by: james | last post by:
I am trying to use Filestream to read a file ( .DAT) that contains values in HEX that I want to convert to text. I know the different offset addresses for each portion of the data I am trying to...
0
by: dphill | last post by:
Hello all I am a beginner .Net programmer so please forgive my ignorance. In brief, I am trying to read from xml file stored in a SQL database table’s field. This is what I used to create...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
14
by: Zoro | last post by:
My task is to read html files from disk and save them onto SQL Server database field. I have created an nvarchar(max) field to hold them. The problem is that some characters, particularly html...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.