473,399 Members | 3,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

loop through tables inside .mdb file using VB.NET

115 100+
i'm using VB.NET and Microsoft Access.

and in one of my Access table is called Emp.mdb. and in that Emp.mdb i have lots of tables like MD1, MD2,......MD58 and MB1,MB2,......MB67 and some other tables too.

so when a button is pressed i need to check all the tables MD# and MB# and retrive some data to create an XML. and other tables were also there, but i don't need to check that tables. and the Number of MD tables and MB tables varies. so i need to check all the tables with MB# and MB#.


for checking Single table i used this code. how can i loop through all the tables MB# and MD# in Emp.mdb.

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = "C:\Program\Emp.mdb"
  2. If File.Exists(TextBox1.Text) Then
  3.             Dim strSQL As String = "Select ItemID,pl11,pl12 from MG10 where ItemID <> 0"
  4.             Dim myConnection As New OleDbConnection(strConn)
  5.             myConnection.Open()
  6.             Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
  7.             Dim myReader As OleDbDataReader = myCommand.ExecuteReader
  8.  
  9.             Dim myXWriter As XmlTextWriter
  10.             Dim myWriter As StreamWriter
  11.             Dim myStream As MemoryStream
  12.             myStream = New MemoryStream
  13.  
  14.             myXWriter = New XmlTextWriter(myStream, Encoding.UTF8)
  15.             myXWriter.Formatting = Formatting.Indented
  16.             myXWriter.Indentation = 2
  17.  
  18.             myXWriter.WriteStartDocument()
  19.             myXWriter.WriteStartElement("Employee")
  20.  
  21.            While myReader.Read
  22.                 myXWriter.WriteStartElement("Item")
  23.                 myXWriter.WriteAttributeString("CV", myReader(0))
  24.                 myXWriter.WriteAttributeString("PL1", myReader(1))
  25.                myXWriter.WriteAttributeString("PL2", myReader(2))
  26.                 myXWriter.WriteEndElement()
  27.             End While
  28.  
  29.             myXWriter.WriteFullEndElement()
  30.             myXWriter.WriteFullEndElement()
  31.             myXWriter.WriteEndDocument()
  32.             myXWriter.Flush()
  33.  
  34.            myStream.Seek(0, SeekOrigin.Begin)
  35.  
  36.             Dim strConfig2 As String = New StreamReader(myStream).ReadToEnd()
  37.             myWriter = File.CreateText("C:\Example.xml")
  38.             myWriter.WriteLine(strConfig2)
  39.             myWriter.Close()
  40.         End If
  41.  
  42.  
  43.  
if you have any idea please let me know. and if you can provide an example then it will be great helpfull for me.

thanks in advanace.
Sep 24 '07 #1
1 2383
remya1000
115 100+
Heah its working too.... here is the code that works....


Dim myConnection As New OleDbConnection(strConn)
myConnection.Open()

Dim schemaTable As DataTable
schemaTable = myConnection.GetOleDbSchemaTable(OleDb.OleDbSchema Guid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})

Dim myXWriter As XmlTextWriter
Dim myWriter As StreamWriter
Dim myStream As MemoryStream

myStream = New MemoryStream
myXWriter = New XmlTextWriter(myStream, Encoding.UTF8)

myXWriter.Formatting = Formatting.Indented
myXWriter.Indentation = 2

Dim i As Integer
For i = 0 To schemaTable.Rows.Count - 1
Dim pTableName As String = schemaTable.Rows(i)!TABLE_NAME.ToString
If Microsoft.VisualBasic.Left(pTableName, 2) = "MD" Then
Dim strSQL As String = "Select ItemID,pl1 from " & pTableName & " where ItemID <> 0"
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader
While myReader.Read
myXWriter.WriteStartElement("MenuItem")
myXWriter.WriteAttributeString("CV", myReader(0))
myXWriter.WriteAttributeString("PL1", myReader(1))
myXWriter.WriteEndElement()
End While
myReader.Close()
ElseIf Microsoft.VisualBasic.Left(pTableName, 2) = "MB" Then
Dim strSQL As String = "Select ItemID,pl1 from " & pTableName & " where ItemID <> 0"
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
Dim myReader As OleDbDataReader = myCommand.ExecuteReader
While myReader.Read
myXWriter.WriteStartElement("MenuItem")
myXWriter.WriteAttributeString("CV", myReader(0))
myXWriter.WriteAttributeString("PL1", myReader(1))
myXWriter.WriteEndElement()
End While
myReader.Close()
End If
Next

myXWriter.WriteEndDocument()
myXWriter.Flush()

myStream.Seek(0, SeekOrigin.Begin)
Dim strConfig2 As String = New StreamReader(myStream).ReadToEnd()
myWriter = File.CreateText("C:\Program\Example.xml")
myWriter.WriteLine(strConfig2)
myWriter.Close()
Sep 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Anand Pillai | last post by:
This is for folks who are familiar with asynchronous event handling in Python using the asyncore module. If you have ever used the asyncore module, you will realize that it's event loop does not...
11
by: John Collyer | last post by:
Hi, In assembly language you can use a lookup table to call functions. 1. Lookup function address in table 2. Call the function Like: CALL FUNCTION
2
by: dSchwartz | last post by:
I need help adding a column to a dataset, but its a little bit more complicated then just that. Here's the situation: I have many xml files in one directory, each which represent a newsletter. I...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
7
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
16
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataAdapter. For every record in tblA where colB = 'abc', I want to update the value in colA. In VB6, using ADO I can loop thru the recordset,set the...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
4
by: toddlahman | last post by:
I am using two while loops that are nested. The first loop (post name) returns the full column of results, but the second (post modified) only returns the first row of the column. Is there another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.