|
-
May 6th, 2010, 05:00 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Quick question about MySQL in vb.net 2008
It it possible in vb.net to run a MySql command like you would do in MySQL
or SQL?
like insert and update statements and also to create a table in the db?
If yes, how could I do this?
-
May 6th, 2010, 05:06 AM
#2
Re: Quick question about MySQL in vb.net 2008
of course did you d/led the mysql .net connector?
http://dev.mysql.com/downloads/connector/net/
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
May 6th, 2010, 05:17 AM
#3
Thread Starter
Addicted Member
Re: Quick question about MySQL in vb.net 2008
Sorry I don't understand the term "d/led".
If what you are asking if I have a MySQL client installed for vb, yes i have.
Can you perhaps give me an example of code where you connect to a MySQL database and then , say insert a new row into a table.
F.Y.I. ---->> This is the dataTable that I use.
vb Code:
Public Function ConnectMe(ByVal TableName As String) As DataTable Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321" Dim cmd As String = "SELECT * FROM " & TableName Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn) ad.GetFillParameters() ad.Fill(topics) Dim dr As DataRow Dim dt As DataTable dt = topics.Tables(0) intSetArray = dt.Rows.Count ReDim names(intSetArray, 4) For Each dr In dt.Rows names(i, 1) = dr(1) 'Username names(i, 2) = dr(2) 'Password names(i, 3) = dr(3) 'Active names(i, 4) = dr(4) 'Accesslevel i += 1 Next topics.Dispose() ConnectMe = topics.Tables(0) End Function
I don't use this datatable all the time, only for some aspects of my program. I also make use of the components in the toolbox
-
May 6th, 2010, 05:18 AM
#4
Thread Starter
Addicted Member
Re: Quick question about MySQL in vb.net 2008
Sorry I don't understand the term "d/led".
If what you are asking if I have a MySQL client installed for vb, yes i have.
Can you perhaps give me an example of code where you connect to a MySQL database and then , say insert a new row into a table.
F.Y.I. ---->> This is the dataTable that I use.
vb Code:
Public Function ConnectMe(ByVal TableName As String) As DataTable
Dim conn As String = "Server=192.168.0.36;Port=3306;Database=wc;Uid=root;Pwd=123454321"
Dim cmd As String = "SELECT * FROM " & TableName
Dim ad As New MySql.Data.MySqlClient.MySqlDataAdapter(cmd, conn)
ad.GetFillParameters()
ad.Fill(topics)
Dim dr As DataRow
Dim dt As DataTable
dt = topics.Tables(0)
intSetArray = dt.Rows.Count
ReDim names(intSetArray, 4)
For Each dr In dt.Rows
names(i, 1) = dr(1) 'Username
names(i, 2) = dr(2) 'Password
names(i, 3) = dr(3) 'Active
names(i, 4) = dr(4) 'Accesslevel
i += 1
Next
topics.Dispose()
ConnectMe = topics.Tables(0)
End Function
I don't use this datatable all the time, only for some aspects of my program. I also make use of the components in the toolbox
-
May 6th, 2010, 05:25 AM
#5
Re: Quick question about MySQL in vb.net 2008
this is how i connect to mysql db
Code:
Using connection as new MySqlConnection("ConnectionString")
Using command as new MySqlCommand("YOUR QUERY",connection
command.parameters.AddWithValue("MyParam",1)
connection.open()
commend.ExecuteScalaer/ExecuteNonQuery/ExecuteReader (or whatever)
end using
End Using
i wrote it from the top of my head since i don't have the code here i also use C# so you might need some tweaking
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
May 6th, 2010, 06:13 AM
#6
Re: [RESOLVED] Quick question about MySQL in vb.net 2008
Hey,
It's a small point, but in my opinion, your method is poorly named. You have a method called ConnectMe, but in actual fact, that method is connecting to the database, executing a command, and returning a result.
You may want to think about refactoring that.
Gary
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
|