首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

xml文件保存用户名和密码,该如何解决

2011-12-31 
xml文件保存用户名和密码有winform应用程序,登录界面输入用户名和密码,当保存密码时用xml文件保存密码(用

xml文件保存用户名和密码
有winform应用程序,登录界面输入用户名和密码,当保存密码时用xml文件保存密码

(用户名和密码与数据库的要吻合)下次登录输入用户名,到xml文件寻找与之匹配的

密码并显示在密码栏。

当不保存密码时,要将xml文件中匹配的用户名和密码删除。

我对操作xml文件不熟,能给简要介绍一下到该的操作过程吗?

[解决办法]
我用的做法是在设置里面添加用户名和密码的记录项,这样比较方便
[解决办法]
Imports System.Xml
Imports System.Collections

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.WriteXML()
Dim mysetting As Hashtable
mysetting = Me.ReadXML()
End Sub

Private Sub WriteXML()

Dim aaa As New XmlTextWriter( "setting.xml ", System.Text.Encoding.UTF8)

aaa.WriteStartDocument()

aaa.Formatting = Formatting.Indented
aaa.Indentation = 4
aaa.WriteComment( "Created By snto // " + DateTime.Now)

aaa.WriteStartElement( "root ")
aaa.WriteAttributeString( "Attribute1 ", "Attribute1 ")


aaa.WriteStartElement( "a1 ")
aaa.WriteValue(100)
aaa.WriteEndElement()

aaa.WriteStartElement( "a2 ")
aaa.WriteValue(200)
aaa.WriteEndElement()

aaa.WriteStartElement( "a3 ")
aaa.WriteValue(300)
aaa.WriteEndElement()

aaa.WriteStartElement( "a4 ")
aaa.WriteValue( "400 ")
aaa.WriteEndElement()

aaa.WriteEndElement()

aaa.Flush()
aaa.Close()

End Sub

Private Function ReadXML() As Hashtable
Dim XmlDoc As New XmlDocument
Dim XmlNode As XmlNode
Dim temphash As New Hashtable
XmlDoc.Load( "setting.xml ")

XmlNode = XmlDoc.SelectSingleNode( "//root ")
temphash.Add( "Attribute1 ", XmlNode.Attributes( "Attribute1 ").InnerText.ToString)
XmlNode = XmlDoc.SelectSingleNode( "//root ")
For Each Xml As XmlElement In XmlNode
temphash.Add(Xml.Name, Xml.InnerText.ToString)
Next
Return temphash
End Function
End Class

[解决办法]
没有什么具体要求
关键是你自己定义的东西 你自己要知道就行了
[解决办法]

'*****************XML文件内容***********************
<?xml version= "1.0 " encoding= "gb2312 " standalone= "yes "?>
<!--程序配置文件,请不要手动修改!-->
<Config>
<DBS> .\Data.mdb </DBS>
<DBC> SF </DBC>
</Config>

'***********************用来读取XML配置文件**********************
Public Function XmlDocReadCFG() As Boolean
Try
Dim XmlDoc As New Xml.XmlDocument
Dim XmlRead As Xml.XmlNode
Dim XmlSelect As Xml.XmlNode
XmlDoc.Load(Application.StartupPath & "/Config.xml ")
XmlRead = XmlDoc.DocumentElement
XmlSelect = XmlRead.SelectSingleNode( "/Config/DBS ")
CFG(0) = XmlSelect.InnerText.ToString
XmlSelect = XmlRead.SelectSingleNode( "/Config/DBC ")
CFG(1) = XmlSelect.InnerText.ToString
Return True


Catch ex As Exception
CFG(0) = Application.StartupPath & "\Data.mdb "
CFG(1) = "SF "
Return True
End Try
End Function

'***********************用来写入XML配置文件**********************
Public Function XmlDocWriteCFG() As Boolean
Dim XmlDoc As New Xml.XmlTextWriter(Application.StartupPath & "/Config.xml ", System.Text.Encoding.GetEncoding( "gb2312 "))
XmlDoc.Formatting = Xml.Formatting.Indented
Try
With XmlDoc
.WriteStartDocument(True)
.WriteComment( "程序配置文件,请不要手动修改! ")
.WriteStartElement( "Config ")
.WriteElementString( "DBS ", CFG(0))
.WriteElementString( "DBC ", CFG(1))
.WriteEndDocument()
.Close()
End With
MsgBox( "保存成功,重新启动程序方能生效 ", MsgBoxStyle.Information)
Return True
Catch ex As Exception
MsgBox( "保存失败: " & ex.Message.ToString, MsgBoxStyle.Critical)
Return False
End Try
End Function

热点排行