Write XML in VB.net
Write XML in Vb.net Using Entity Data Model
Code for VB
Imports ProjectManager.ProjectManagerModel
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim DataObj As Customer
Dim Cust As String = txtCustCode.Text
Using modelContext As New ProjectManagerEntities
DataObj = modelContext.Customers.Where(Function(C) C.CustId = CDbl(Cust)).FirstOrDefault()
txtCustCode.Text = DataObj.CustId.ToString
txtCustAlias.Text = DataObj.Account.Alias
txtCustName.Text = DataObj.CustName
End Using
End Sub
Private Sub btnXML_Click(sender As System.Object, e As System.EventArgs) Handles btnXML.Click
Dim DataObj As Customer
Dim Cust As String = txtCustCode.Text
Using modelContext As New ProjectManagerEntities
DataObj = modelContext.Customers.Where(Function(C) C.CustId = CDbl(Cust)).FirstOrDefault()
' Create XmlWriterSettings.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
' Create XmlWriter.
Using writer As XmlWriter = XmlWriter.Create("C:\Customer.xml", settings)
' Begin writing.
writer.WriteStartDocument()
writer.WriteStartElement("Customers") ' Root.
writer.WriteStartElement("Customer")
writer.WriteElementString("CustId", DataObj.CustId.ToString)
writer.WriteElementString("CustAlias", DataObj.Account.Alias)
writer.WriteElementString("CustName", DataObj.CustName)
writer.WriteEndElement()
' End document.
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
End Using
End Sub
End Class
Output...
Write XML in Vb.net Using Entity Data Model
Code for VB
Imports ProjectManager.ProjectManagerModel
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim DataObj As Customer
Dim Cust As String = txtCustCode.Text
Using modelContext As New ProjectManagerEntities
DataObj = modelContext.Customers.Where(Function(C) C.CustId = CDbl(Cust)).FirstOrDefault()
txtCustCode.Text = DataObj.CustId.ToString
txtCustAlias.Text = DataObj.Account.Alias
txtCustName.Text = DataObj.CustName
End Using
End Sub
Private Sub btnXML_Click(sender As System.Object, e As System.EventArgs) Handles btnXML.Click
Dim DataObj As Customer
Dim Cust As String = txtCustCode.Text
Using modelContext As New ProjectManagerEntities
DataObj = modelContext.Customers.Where(Function(C) C.CustId = CDbl(Cust)).FirstOrDefault()
' Create XmlWriterSettings.
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
' Create XmlWriter.
Using writer As XmlWriter = XmlWriter.Create("C:\Customer.xml", settings)
' Begin writing.
writer.WriteStartDocument()
writer.WriteStartElement("Customers") ' Root.
writer.WriteStartElement("Customer")
writer.WriteElementString("CustId", DataObj.CustId.ToString)
writer.WriteElementString("CustAlias", DataObj.Account.Alias)
writer.WriteElementString("CustName", DataObj.CustName)
writer.WriteEndElement()
' End document.
writer.WriteEndElement()
writer.WriteEndDocument()
End Using
End Using
End Sub
End Class
Output...
0 comments:
Post a Comment