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. -
TextBox1.Text = "C:\Program\Emp.mdb"
-
If File.Exists(TextBox1.Text) Then
-
Dim strSQL As String = "Select ItemID,pl11,pl12 from MG10 where ItemID <> 0"
-
Dim myConnection As New OleDbConnection(strConn)
-
myConnection.Open()
-
Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
-
Dim myReader As OleDbDataReader = myCommand.ExecuteReader
-
-
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
-
-
myXWriter.WriteStartDocument()
-
myXWriter.WriteStartElement("Employee")
-
-
While myReader.Read
-
myXWriter.WriteStartElement("Item")
-
myXWriter.WriteAttributeString("CV", myReader(0))
-
myXWriter.WriteAttributeString("PL1", myReader(1))
-
myXWriter.WriteAttributeString("PL2", myReader(2))
-
myXWriter.WriteEndElement()
-
End While
-
-
myXWriter.WriteFullEndElement()
-
myXWriter.WriteFullEndElement()
-
myXWriter.WriteEndDocument()
-
myXWriter.Flush()
-
-
myStream.Seek(0, SeekOrigin.Begin)
-
-
Dim strConfig2 As String = New StreamReader(myStream).ReadToEnd()
-
myWriter = File.CreateText("C:\Example.xml")
-
myWriter.WriteLine(strConfig2)
-
myWriter.Close()
-
End If
-
-
-
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.
1 2383
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()
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
| |