如何在xml中绑定数据库值 [英] How to bind database values in xml

查看:79
本文介绍了如何在xml中绑定数据库值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将数据库值绑定到xml,并将xml文件绑定到图表.
我尝试了静态值.它仅接受X轴值.但是它不显示Y轴值.我也没有得到任何错误.我必须在vb.net 2.0 Windows窗体中执行此概念.如果有人知道这一点,请帮助我.

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.

推荐答案

下面的代码是我所获得的项目的状态.
它的作用是使您可以轻松地将数据设置为变量,然后设置为.xml文件.

我不知道您要寻找的答案是什么,因为它是用3.5而不是2.0编写的

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

 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



我认为您可以将数据读取和写入数据库,因此您应该可以String1 = WriteX2:xmlread()或其他东西.



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


这篇关于如何在xml中绑定数据库值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆