|
-
Jan 18th, 2012, 04:44 PM
#1
Thread Starter
Addicted Member
Querie mysql and extract
I'm trying to querie a mysql database and extract two fields. I'd like to store the output in a text file.
For example:
mysql database would be
Field1 Field2
a1 a2
b1 b2
Output Text File
a1,a2
b1, b2
I'm not familiar with the VB2008 commands to do this. I've written codes using the below commands to extract a single record tied to a single idnum. How do I extract the entire database data (all the records, no idnum)?
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As MySqlDataReader
Dim SQL As String
Dim table_name As String = "website_products"
SQL = "SELECT * FROM " & table_name & " WHERE `idnum`=" & TextBox2.Text
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myData = myCommand.ExecuteReader()
myData.Read()
TextBox3.Text = myData.GetString("meta_description")
I'm using the below code to connect to the mysql database.
Dim conn As New MySqlConnection
Private Function Connect(ByVal server As String, ByRef user As String, ByRef password As String, ByRef database As String)
' Connection string with MySQL Info
conn.ConnectionString = "server=" + server + ";" _
& "user id=" + user + ";" _
& "password=" + password + ";" _
& "database=" + database + ";"
Try
conn.Open()
Return True
Catch ex As MySqlException
Return MsgBox(ex.Message)
End Try
End Function
-
Jan 18th, 2012, 06:21 PM
#2
Re: Querie mysql and extract
The part in your SQL that says:
Code:
... & " WHERE `idnum`=" & TextBox2.Text
... Remove it.
-
Jan 18th, 2012, 07:17 PM
#3
Thread Starter
Addicted Member
Re: Querie mysql and extract
How do I get the 2nd, 3rd, etc record in the database?
TextBox3.Text = myData.GetString("meta_description")
will only get the first record.
-
Jan 18th, 2012, 07:39 PM
#4
Frenzied Member
Re: Querie mysql and extract
i would normally walk through the table writing out the appropiate parts to a file
its a while not end of table
record.movenext
type arrangement
here to help more if needed
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|