Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   How to store XML data in ACCESS DB using VB6 (http://www.programmingforums.org/showthread.php?t=14845)

kartik07 Jan 1st, 2008 1:33 PM

How to store XML data in ACCESS DB using VB6
 
Hi ,
I am new to VB6 and doing a proj in VB6
I need to extract data from an XML file and store it in a
database table(MS ACCESS).Lets say Tablename=XYZ
I used the code in module modmain but I am getting an error
saying "could not find installable ISAM".
The MS ACCESS Table contains following fields:
1.Machine ID
2.Fault id
3.Date of Occurence
4.Time of Occurence

consider the XML File
<MACHINE>
<ID>
100
<FAULTID>F001</FAULTID>
<DOO>06.42.19</DOO>
<TOO>06.02.1997</TOO>
</ID>
<ID>
100
<FAULTID>F002</FAULTID>
<DOO>05.12.19</DOO>
<TOO>06.02.1997</TOO>
</ID>
</MACHINE>



AL the above values need to be stored in ACCESS table.I used XML4 here.
:

Public g_ConDB As ADODB.Connection
Public g_domXML As DOMDocument40
Public g_rsFaults As Recordset


Public Sub Main()
  ConnectDB
  LoadXML
  OpenRS
  AddFaultRecords
  CloseRS
  CloseDB
End Sub

Public Sub ConnectDB()

  Set g_ConDB = New Connection
  g_ConDB.Open "provider = Microsoft.Jet.OLEDB.4.0; datasource = F:\xml2test\db1.mdb"
End Sub

Public Sub LoadXML()
  Set g_domXML = New DOMDocument40
  g_domXML.Load "F:\xml2test\MS1.xml"
End Sub

Public Sub OpenRS()
  Set g_rsFaults = New Recordset
  g_rsFaults.LockType = adlockpesimistic
  Set g_rsFaults.ActiveConnection = g_ConDB
  g_rsFaults.Open "Select * from xyz"

End Sub

Public Sub AddFaultRecords()
  Dim ndFault As IXMLDOMNode
  Dim lngMachineID As Long
  Dim FaultID As String
  Dim dtDate As Date
  Dim strTime As String
  For Each ndFault In g_domXML.selectNodes("/MACHINE")
    lngMachineID = Val(ndFault.selectSingleNode("ID").Text)
    FaultID = ndFault.selectSingleNode("FAULTID").Text
    dtDate = CDate(ndFault.selectSingleNode("DOO").Text)
    strTime = ndFault.selectSingleNode("TOO").Text

    g_rsFaults.findfirst "[machine id]=" & lngMachineID & " and [Fault id]='" & FaultID & "'"
    If g_rsFaults.EOF Then
      g_rsFaults.AddNew
      g_rsFaults("Machine ID") = lngMachineID
      g_rsFaults("Fault ID") = FaultID
    End If

    g_rsFaults("Date Of Occurence") = dtDate
    g_rsFaults("Time of Occurence") = strTime
    g_rsFaults.Update
  Next ndFault


End Sub
Private Sub CloseRS()
  g_rsFaults.Close
End Sub
Private Sub CloseDB()
  g_ConDB.Close
End Sub



Can someone rectify the error & if possible can explain the meaning of this code,not the whole thing but atleast the gist.
I need it urgently.

kartik07 Jan 1st, 2008 1:35 PM

Re: How to store XML data in ACCESS DB using VB6
 
I used start mode from submain & used Microsoft Active DAta Objects (2.6) & msxml4


All times are GMT -5. The time now is 3:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC