'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
Go Back  Xtreme Visual Basic Talk > > > 'Search' MySQL from VB vs VB.Net


Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2005, 10:40 PM
veebeenewbie veebeenewbie is offline
Newcomer
 
Join Date: Feb 2005
Posts: 18
Default 'Search' MySQL from VB vs VB.Net


Hi.

I'm new to VB and VB.Net. I would like to ask on how do I search for a particular data in mySQL in VB.Net. I would like to change my application from VB6 to VB.Net.

In VB 6, this is what I did:

Set rec = New ADODB.Recordset
SQL = "Select * from comp.record where comp.record.comp_ID = ' " &txtSearch& " ' "
rec.Open, conn, adOpenStatic, adLockOptimistic, adCmdText

With rec
If txtSearch = rec.Fields("comp_ID") Then
txtName.Text = Fields("name")
txtNick.Text = Fields("nickname")
End If
End With

rec.Close


Could anyone advice me on how should I do this in VB.Net, since I couldn't "Dim" the recordset.

Thanks.
Reply With Quote
  #2  
Old 08-09-2005, 09:11 AM
jayceepoo's Avatar
jayceepoo jayceepoo is offline
Senior Contributor
 
Join Date: Jul 2002
Posts: 1,021
Default

Search the forum or MSDN for OleDbConnection to connect to the database, use an OleDbCommand to set up your query, and use an OleDbDataReader to read the information returned from your OleDbCommand object's ExecuteReader() function.
__________________
Jayceepoo

"I recently went to a new doctor and noticed he was located in something called the Professional Building. I felt better right away." - George Carlin
Reply With Quote
  #3  
Old 08-09-2005, 10:46 PM
veebeenewbie veebeenewbie is offline
Newcomer
 
Join Date: Feb 2005
Posts: 18
Default

well, i've tried doing it by looking at some examples:

maybe this can help others who is looking for this specific function...


Code:
Dim myConn As New MySqlConnection Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter Dim myData As New DataTable Dim myReader As MySqlDataReader SQL = "SELECT * FROM database.barcode b WHERE b.ID = '" & txtSearch.Text & "' " myConn = New MySqlConnection myConn.ConnectionString = "SERVER=localhost;" & _ "USER ID=root;" & _ "PASSWORD=password;" & _ "DATABASE=database;" Try myConn.Open() 'MessageBox.Show("connection opened!") Try myCommand.Connection = myConn myCommand.CommandText = SQL myAdapter.SelectCommand = myCommand myAdapter.Fill(myData) myReader = myCommand.ExecuteReader While myReader.Read txtcompId.Text = myReader.Item("comp_ID").ToString() txtSectionId.Text = myReader.Item("section_ID").ToString txtDeptId.Text = myReader.Item("dept_ID").ToString() txtId.Text = myReader.Item("ID").ToString() txtLocation.Text = myReader.Item("location").ToString() txtName.Text = myReader.Item("name").ToString() End While 'MessageBox.Show("Good") Catch ex As Exception MessageBox.Show("Error querying!") End Try myConn.Close() Catch myError As MySqlException MessageBox.Show("Error connecting!" & myError.Message) Finally myConn.Dispose() End Try

Last edited by wayneph; 08-10-2005 at 07:46 AM. Reason: please use [vb][/vb] tags for posting code
Reply With Quote
  #4  
Old 08-10-2005, 07:48 AM
wayneph's Avatar
wayneph'Search' MySQL from VB vs VB.Net wayneph is offline
Web Junkie

Retired Moderator
* Expert *
 
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
Default

The SQLConnection object will only work with SQL Server (and MSDE). You need to use the OleDb objects as jayceepoo suggested to work with MySQL.
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
Reply With Quote
  #5  
Old 08-12-2005, 10:06 AM
MKoslof's Avatar
MKoslof'Search' MySQL from VB vs VB.Net MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

No, it looks like he is using the .Net Provider for MYSQL, which is the best way to go:

Code:
Dim myConn As New MySqlConnection Dim myCommand As New MySqlCommand Dim myAdapter As New MySqlDataAdapter

What data provider are you importing? What managed code data dll are you importing into your application? If you are using the .Net Connector for MySQL (downloaded from their website) you need to also pass in the port to your connection string. MySQL has some nice examples on their website regarding how to use this data access class.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #6  
Old 08-15-2005, 03:26 AM
veebeenewbie veebeenewbie is offline
Newcomer
 
Join Date: Feb 2005
Posts: 18
Default

Yes... I am using the .Net Provider for MySQL.

I add .Net Connector as per this article... maybe this would help some of you out there too....

http://dev.mysql.com/doc/mysql/en/co...net-using.html

yup.... MKoslof is rite!

Thanks guys
Reply With Quote
  #7  
Old 08-15-2005, 02:56 PM
SharkBait's Avatar
SharkBait SharkBait is offline
Contributor
 
Join Date: Dec 2004
Location: BC, Canada
Posts: 494
Default

Quote:
Originally Posted by veebeenewbie
Yes... I am using the .Net Provider for MySQL.

I add .Net Connector as per this article... maybe this would help some of you out there too....

http://dev.mysql.com/doc/mysql/en/co...net-using.html

yup.... MKoslof is rite!

Thanks guys
I've been using the above connector as well for my MySQL.

Now to play with it a bit more to understand it as I too come from the VB6 kinda stuff
__________________
SharkBait
Living on the WestCoast of Canada
My journey to blogging success: www.tyleringram.com
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net 'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
 
'Search' MySQL from VB vs VB.Net
'Search' MySQL from VB vs VB.Net
 
-->