Db To Xml, Xml To Db, DbToXml, v1.52, crack, download, get, install, .Net, C#, VB.NET, Java, XML Codegenerator, XSD Code Generator, Biztalk Code Generator, Biztalk Adapter, Adapter for Biztalk, EAI, B2B, XSD To XDR
Home Support Forum


DbToXml Help
Code Samples.






DbToXml Help | C# | VB.NET | VB.60 | Java | SQL | XML | XSD | Biz Doc | DTD








vb .NET code
VB.NET code example:
 
 
'To test this sample you will need to download and Install ODBC.NET Data Provider
'http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/MSDN-FILES/027/001/668/msdncompositedoc.xml&frame=true
'created by max
 
Imports System
Imports System.IO
Imports System.Data
Imports System.Xml
Imports System.Collections
Imports System.Data.SqlClient
Imports Microsoft.Data.Odbc
Imports System.Data.Common
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports System.Xml.Serialization
 
 
Namespace school
      <Serializable(), XmlRoot("PAYMENTS")>  _
      Public Class PAYMENTSClass
            Private dbconn As IDbConnection
            Private da As IDbDataAdapter
            Private ds As DataSet
            
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private dPaymentDate As DateTime
            <XmlElement(ElementName := "PaymentDate", DataType := "date", [Namespace] := "school")>  _
            Public Property PaymentDate() As DateTime
                  Get
                        Return dPaymentDate
                  End Get
                  Set
                        dPaymentDate = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nInvoiceID As Double
            <XmlElement(ElementName := "InvoiceID", DataType := "int", [Namespace] := "school")>  _
            Public Property InvoiceID() As Double
                  Get
                        Return nInvoiceID
                  End Get
                  Set
                        nInvoiceID = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nAmount As Double
            <XmlElement(ElementName := "Amount", DataType := "int", [Namespace] := "school")>  _
            Public Property Amount() As Double
                  Get
                        Return nAmount
                  End Get
                  Set
                        nAmount = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private sAmountCurrency As String
            <XmlElement(ElementName := "AmountCurrency", DataType := "string", [Namespace] := "school")>  _
            Public Property AmountCurrency() As String
                  Get
                        Return sAmountCurrency
                  End Get
                  Set
                        sAmountCurrency = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nPaymentType As Double
            <XmlElement(ElementName := "PaymentType", DataType := "int", [Namespace] := "school")>  _
            Public Property PaymentType() As Double
                  Get
                        Return nPaymentType
                  End Get
                  Set
                        nPaymentType = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nMonthID As Double
            <XmlElement(ElementName := "MonthID", DataType := "int", [Namespace] := "school")>  _
            Public Property MonthID() As Double
                  Get
                        Return nMonthID
                  End Get
                  Set
                        nMonthID = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nYear As Double
            <XmlElement(ElementName := "Year", DataType := "int", [Namespace] := "school")>  _
            Public Property Year() As Double
                  Get
                        Return nYear
                  End Get
                  Set
                        nYear = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private sNotes As String
            <XmlElement(ElementName := "Notes", DataType := "string", [Namespace] := "school")>  _
            Public Property Notes() As String
                  Get
                        Return sNotes
                  End Get
                  Set
                        sNotes = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nContactID As Double
            <XmlElement(ElementName := "ContactID", DataType := "int", [Namespace] := "school")>  _
            Public Property ContactID() As Double
                  Get
                        Return nContactID
                  End Get
                  Set
                        nContactID = value
                  End Set
            End Property
 
            '<summary>
            'Access properties for CertID field of Certification table
            '</summary>
            Private nPaymentID As Double
            <XmlElement(ElementName := "PaymentID", DataType := "int", [Namespace] := "school")>  _
            Public Property PaymentID() As Double
                  Get
                        Return nPaymentID
                  End Get
                  Set
                        nPaymentID = value
                  End Set
            End Property
 
 
      
         '<summary>
            'Default constructor creates ODBCConnection and initialize object.
            '</summary>
            Public Sub New()
                  Dim cb As OdbcCommandBuilder
                  getODBCConnection()
                  da = New OdbcDataAdapter()
                  init()
              cb = New OdbcCommandBuilder(CType(da, OdbcDataAdapter))
                  cb.RefreshSchema()
            End Sub 'New
            
            '<summary>
            'Constructor uses external SqlConnection to initialize object.
            '</summary>
            Public Sub New(extDbConn As SqlConnection)
                  Dim cb As SqlCommandBuilder
                  dbconn = extDbConn
                  da = New SqlDataAdapter()
                  init()
                  cb = New SqlCommandBuilder(CType(da, SqlDataAdapter))
                  cb.RefreshSchema()
            End Sub 'New
            
            
            '<summary>
            'Constructor uses external OleDbConnection to initialize object.
            '</summary>
            Public Sub New(extDbConn As OleDbConnection)
                  Dim cb As OleDbCommandBuilder
                  dbconn = extDbConn
                  da = New OleDbDataAdapter()
                  init()
                  cb = New OleDbCommandBuilder(CType(da, OleDbDataAdapter))
                  cb.RefreshSchema()
            End Sub 'New
            
            
            '<summary>
            'Constructor uses external ODBCConnection to initialize object.
            '</summary>
            Public Sub New(extDbConn As OdbcConnection)
      Dim cb As OdbcCommandBuilder
                  dbconn = extDbConn
                  da = New OdbcDataAdapter()
                  init()
                  cb = New OdbcCommandBuilder(CType(da, OdbcDataAdapter))
                  cb.RefreshSchema()
            End Sub 'New
            
            
            '<summary>
            'Loads object properties and DataSet by primary key.
            '</summary>
            Public Sub load(dPaymentDate_PK As DateTime)
                  Try
                        'CType(da.SelectCommand.Parameters(0), IDataParameter).Value = i_CertID_PK
                        
                        CType(da.SelectCommand.Parameters(0), IDataParameter).Value = dPaymentDate_PK
                        da.Fill(ds)
                        ds2object()
                  Catch e As Exception
                        handleException(e)
                        Return
                  End Try
            End Sub 'load
            
            
            '<summary>
            'Updates the DataSet from the object
            'properties and submit changes to the database.
            '</summary>
            Public Sub update()
                  Try
                        object2ds()
                        da.Update(ds)
                  Catch e As Exception
                        handleException(e)
                        Return
                  End Try
            End Sub 'update
            
            '<summary>
            'Creates new record in the DataSet, populate it from object
            'properties and submit changes to the database.
            '</summary>
            Public Sub insert()
                  Try
                        ds.Tables(0).Clear()
                        ds.Tables(0).Rows.Add(ds.Tables(0).NewRow())
                        object2ds()
                        da.Update(ds)
                  Catch e As Exception
                        handleException(e)
                        Return
                  End Try
            End Sub 'insert
            
            
            '<summary>
            'Populate Object properties from the DataSet.
            '</summary>
            Private Sub ds2object()
                  Dim row As DataRow = ds.Tables(0).Rows(0)
                        
                  If row.IsNull("PaymentDate") Then
                        dPaymentDate = 0
                  Else
                        dPaymentDate = [DateTime].Parse(row("PaymentDate").ToString())
                  End If
                  If row.IsNull("InvoiceID") Then
                        nInvoiceID = 0
                  Else
                        nInvoiceID = [Double].Parse(row("InvoiceID").ToString())
                  End If
                  If row.IsNull("Amount") Then
                        nAmount = 0
                  Else
                        nAmount = [Double].Parse(row("Amount").ToString())
                  End If
                  sAmountCurrency = row("AmountCurrency").ToString()
                  If row.IsNull("PaymentType") Then
                        nPaymentType = 0
                  Else
                        nPaymentType = [Double].Parse(row("PaymentType").ToString())
                  End If
                  If row.IsNull("MonthID") Then
                        nMonthID = 0
                  Else
                        nMonthID = [Double].Parse(row("MonthID").ToString())
                  End If
                  If row.IsNull("Year") Then
                        nYear = 0
                  Else
                        nYear = [Double].Parse(row("Year").ToString())
                  End If
                  sNotes = row("Notes").ToString()
                  If row.IsNull("ContactID") Then
                        nContactID = 0
                  Else
                        nContactID = [Double].Parse(row("ContactID").ToString())
                  End If
                  If row.IsNull("PaymentID") Then
                        nPaymentID = 0
                  Else
                        nPaymentID = [Double].Parse(row("PaymentID").ToString())
                  End If
            End Sub 'ds2object
            
            
            '<summary>
            'Populate DataSet from Object properties.
            '</summary>
            Private Sub object2ds()
                  Dim row As DataRow = ds.Tables(0).Rows(0)
                  row.BeginEdit()
                                    row("PaymentDate") = dPaymentDate
                  row("InvoiceID") = nInvoiceID
                  row("Amount") = nAmount
                  row("AmountCurrency") = sAmountCurrency
                  row("PaymentType") = nPaymentType
                  row("MonthID") = nMonthID
                  row("Year") = nYear
                  row("Notes") = sNotes
                  row("ContactID") = nContactID
                  row("PaymentID") = nPaymentID
 
                  row.EndEdit()
            End Sub 'object2ds
            
            '<summary>
            'Initialize commands.
            '</summary>
            Private Sub init()
                  ds = New DataSet("PAYMENTSDoc")
                  da.SelectCommand = dbconn.CreateCommand()
                  da.SelectCommand.CommandText = "SELECT * FROM Payments where PaymentDate = ? "
                  
                  addParameter(da.SelectCommand, "@PaymentDate",DbType.Date, "PaymentDate")
            End Sub 'init
            
            
            '<summary>
            'Add database parameter to the select command
            '</summary>
            Private Function addParameter(command As IDbCommand, _
             parameterName As String, parameterType As DbType, _
             sourceColumn As String) As IDbDataParameter
                  Dim param As IDbDataParameter = command.CreateParameter()
                  param.ParameterName = parameterName
                  param.DbType = parameterType
                  param.Direction = ParameterDirection.Input
                  param.SourceVersion = DataRowVersion.Current
                  param.SourceColumn = sourceColumn
                  
                  command.Parameters.Add(param)
                  Return param
            End Function 'addParameter
            
            
            '<summary>
            'Generate XML string from the current DataSet
            '</summary>
            Public Function getXml() As String
                  If Not (ds Is Nothing) Then
                        Return ds.GetXml()
                  Else
                        Return ""
                  End If
            End Function 'getXml
            
            
            '<summary>
            'Set properties of the object from XML string
            '</summary>
            Public Sub setXml(sXml As String)
                  If Not (ds Is Nothing) Then
                        ds.ReadXml(New StringReader(sXml))
                        ds2object()
                  End If
            End Sub 'setXml
            
            
            '<summary>
            'Get xml schema from current DataSet
            '</summary>
            Public Function getXmlSchema() As String
                  If Not (ds Is Nothing) Then
                        Return ds.GetXmlSchema()
                  Else
                        Return ""
                  End If
            End Function 'getXmlSchema
            
            
            '<summary>
            'Get Database connection from OleDb connection string
            '</summary>
            Private Function getOleDbConnection() As IDbConnection
                  If dbconn Is Nothing Then
                        Try
dbconn = New OleDbConnection("PROVIDER=MSDASQL;UID=;PWD=;DSN=school;")
                              dbconn.Open()
                        Catch e As Exception
                              handleException(e)
                              Return Nothing
                        End Try
                  End If
                  Return dbconn
            End Function 'getOleDbConnection
            
            
            '<summary>
            'Get Database connection from ODBC connection string
            '</summary>
            Private Function getODBCConnection() As IDbConnection
                  If dbconn Is Nothing Then
                        Try
dbconn = New OdbcConnection("PROVIDER=MSDASQL;UID=;PWD=;DSN=school;")
                              dbconn.Open()
                        Catch e As Exception
                              handleException(e)
                              Return Nothing
                        End Try
                  End If
                  Return dbconn
            End Function 'getODBCConnection
            
            '<summary>
            'Overwrite this method with standard exception handling
            'procedure for your application.
            '</summary>
            Private Sub handleException(e As Exception)
                  MessageBox.Show(e.ToString())
            End Sub 'handleException
 
'        <summary>
'              Test Main method for the CERTIFICATION class.
'        </summary>
'
'        Shared<STAThread()>  _
'        Sub Main()
'                  Dim test As PAYMENTSClass;
'                  test = New CERTIFICATION( _
                          New ODBCConnection("PROVIDER=MSDASQL;UID=;PWD=;DSN=school;"))                  
'                  test.load(1)
'                  MessageBox.Show(test.getXml())
'        End Sub 'Main
'
      End Class 'PAYMENTSClass
End Namespace 'school
 
 





















Download the tool that will generate this code from your existing databse tables now.





WebMethods B2B

Biz Talk

.Net

RozettaNet


Softrus LLC © 1999-2004