473,624 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="CRCPermis sion">
<ToolBars>
<Permission>
<PermissionName >Security Tool Bar</PermissionName>
<GrantAccess>Tr ue</GrantAccess>
</Permission>
<Permission>
<PermissionName >Employee Tool Bar</PermissionName>
<GrantAccess>Tr ue</GrantAccess>
</Permission>
<Permission>
<PermissionName >Case Find Tool Bar</PermissionName>
<GrantAccess>Tr ue</GrantAccess>
</Permission>
<Permission>
<PermissionName >Case Look Up Tool Bar</PermissionName>
<GrantAccess>Tr ue</GrantAccess>
</Permission>
<Permission>
<PermissionName >Allegations Tool Bar</PermissionName>
<GrantAccess>Fa lse</GrantAccess>
</Permission>
<Permission>
<PermissionName >Subjects Tool Bar</PermissionName>
<GrantAccess>Tr ue</GrantAccess>
</Permission>
<Permission>
<PermissionName >Hiring Authority Tool Bar</PermissionName>
<GrantAccess>Fa lse</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.Collecti ons.Generic
Imports System.Componen tModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows. Forms
Imports System.Data.Sql Client
Imports System.Xml
Imports System.Xml.XPat h
Imports System.Data.Sql Types
Imports System.Configur ation
Imports Microsoft.Data. SqlXml
Imports System.Data.Ole Db

Public Class Form1
Dim WithEvents xmldoc2 As Xml.XmlDataDocu ment ' "MAKE GLOBAL"
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim investigationsi nfo 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
investigationsi nfo.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.D ocumentElement
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.SelectNode s("descendant:: ToolBars/Permission")
elemList1 = InvestDataSet.G etElementsByTag Name("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.ChildN odes
If NewItem Then
lv = ListView1.Items .Add(Child.Inne rText)
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.0 0
Microsoft Data Access Components (MDAC) 2000.085.1117.0 0
(xpsp_sp2_rtm.0 40803-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.SelectNode s("descendant:: Document")
elemList1 = InvestDataSet.G etElementsByTag Name("Document" )

Help Please

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

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

Similar topics

0
2639
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 like this: obj1 method1. For example, file1 can be like this: 10 obj1 method1
0
1900
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 contains an image (it can store jpg, bmp, gif, but I don't know what image is stored inside). I want to retrieve the picture stored in the database and identified by a given id and display it in a web page (.aspx). I write in Visual C#, but it does...
3
13378
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 shipment. I download the file from UPS and then use DTS to import the data into SQL. At that point, I have a Crystal report that prints what looks like a regular UPS invoice. The only problem is that I wind up with having to print two...
1
2392
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 the SpServer and Spclient progs against the default database SAMPLE. And everything works.
3
4360
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 contains an image (it can store jpg, bmp, gif, but I don't know what image is stored inside). I want to retrieve the picture stored in the database and identified by a given id and display it in a web page (.aspx). I write in Visual C#, but it does...
8
7252
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 retrieve. But, I am having problems actually reading the data for the number of Bytes that I need to get from each address. Here is some of the code I am currently working with: Dim fsread As FileStream = File.Open(OpenFileDialog1.FileName,...
0
780
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 the table: CREATE TABLE Document ( DocID int IDENTITY NOT NULL, Description nvarchar(50) NOT NULL, DocumentStore xml NOT NULL,
3
2934
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 datatype for the file instead of using IMAGE datatype. I can not use SqlDataReader to read the data. I need your help, Thanks. -David (1) I have a table TestFile for testing: ID int FileName navrchar(255)
14
5753
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 entities, and French/German special characters are lost and/or replaced by a question mark. This is really frustrating. I have tried using StreamReader with ALL the encodings available and none work correctly. Each encoding handles some characters...
2
7644
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 don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.