|
-
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
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
|