Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to bind database values to xml and from xml file to chart.
I tried for static values. It takes X Axis values only. But it doesn't display Y Axis value. I didn't get any error also. I have to do this concept in vb.net 2.0 windows form. If anybody know this please help me.
Posted

1 solution

The code below is state from a project I got.
What it does is it allows you to easily set the data into variables then into the .xml file.

I dont know if is the answer you are looking for as this was written in 3.5 not 2.0

VB
 Public xmlsettingslocation As String = Application.StartupPath & "\Settings.xml"

#Region "Region_XMLSettings"
 odule xmlSettings

    Public ReadX1 As String = Nothing : Public ReadX2 As Boolean = Nothing
    Public ReadX3 As String = Nothing : Public ReadX4 As String = Nothing
    Sub xmlread()
        MessageBox.Show(xmlsettingslocation)
        If File.Exists(xmlsettingslocation) = False Then  Else WriteX1 = "1" : WriteX2 = "True" : WriteX3 = "True" : WriteX4 = "String1" : xmlwrite() ' if Settings.xml does not exist then reset the settings to default

        ' ======READ Settings.xml file to String=======
        Dim fs As FileStream = Nothing : fs = New FileStream(Settings.xmlsettingslocation, FileMode.Open, FileAccess.Read) ' Works
        Dim xsdoc As New XmlDataDocument() : xsdoc.Load(fs)
        Dim xsnode As XmlNodeList = Nothing : xsnode = xsdoc.GetElementsByTagName("Settings")
        Dim ReadX1 As String = Nothing : ReadX1 = xsnode(0).ChildNodes.Item(0).InnerText.Trim() 'ID
        Dim ReadX2 As String = Nothing : ReadX2 = xsnode(0).ChildNodes.Item(1).InnerText.Trim() 'On_Exit_Close_Excel
        Dim ReadX3 As String = Nothing : ReadX3 = xsnode(0).ChildNodes.Item(2).InnerText.Trim() 'Screen_Updates
        Dim ReadX4 As String = Nothing : ReadX4 = xsnode(0).ChildNodes.Item(3).InnerText.Trim() 'Update_Path
        fs.Close() ' Kill the XML Process
        '==============================================
        'Usage   MessageBox.Show("Your String Is: " & ReadX4)
    End Sub

    Public WriteX1 As Integer = CInt(0) : Public WriteX2 As Boolean = Nothing
    Public WriteX3 As Boolean = Nothing : Public WriteX4 As String = Nothing
    Private Sub createNode(ByVal pID As String, ByVal pN1 As String, ByVal pN2 As String, ByVal pN3 As String, ByVal writer As XmlTextWriter)

        ' this is the tree of the XML File!
        writer.WriteStartElement("Settings")

        writer.WriteStartElement("ID")
        writer.WriteString(pID) : writer.WriteEndElement() 'Read: ReadX1 | Write: WriteX1

        writer.WriteStartElement("On_Exit_Close_Excel")
        writer.WriteString(pN1) : writer.WriteEndElement() 'Read: ReadX2 | Write: WriteX2

        writer.WriteStartElement("Screen_Updates")
        writer.WriteString(pN2) : writer.WriteEndElement() 'Read: ReadX3 | Write: WriteX3

        writer.WriteStartElement("Update_Path")
        writer.WriteString(pN3) : writer.WriteEndElement() 'Read: ReadX4 | Write: WriteX4

        writer.WriteEndElement()
    End Sub

    Sub xmlwrite()
        'Usage     WriteX1 = "1" :  WriteX2 = "True" :  WriteX3 = "string1" :  WriteX4 = "string2" : xmlwrite()
        Dim writer As New XmlTextWriter(xmlsettingslocation, Nothing)
        writer.WriteStartDocument(True) : writer.Formatting = Formatting.Indented
        writer.Indentation = 7  ' 2 by default
        writer.WriteStartElement("Table")
        createNode(CStr(WriteX1), CStr(WriteX2), CStr(WriteX3), CStr(WriteX4), writer) 'WORKS!
        WriteX1 = CInt(0) : WriteX2 = Nothing : WriteX3 = Nothing : WriteX3 = Nothing : WriteX4 = Nothing ' un dim the vars for safety
        writer.WriteEndElement() : writer.WriteEndDocument() : writer.Close()
    End Sub

End Module
#End Region 'Region_XMLSettings

'-------------------------------------------------------------------------
Public Class Form_Settings

' Your Code...
    Sub test()
        Call xmlread() ' if the file does not exist then make one with defaults

        ' change the defaults to what ever you want
        'Note all data can be what ever you want and can be stored in any WriteX#
        WriteX1 = "1" : WriteX2 = "True" : WriteX3 = "string1" : WriteX4 = "string2" : xmlwrite()
        'or
        WriteX3 = "Hello World!" : xmlwrite() ' this is for WriteX3, you cant just  WriteX3 = "string" you need the xmlwrite() after you set the string


        ' you can then read the string using this simple example.
          MessageBox.Show("your String Is: " & ReadX3)

    End Sub



End Sub 'Form_Settings


I think you can Read and Write data into your database so you should be able to String1 = WriteX2 : xmlread() or somthing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900