migrate to VB .NET

CharlieChau

Active member
Joined
Jun 15, 2004
Messages
26
Programming Experience
Beginner
Hi,

I have a sample code to access MYSQL by visual basic. How can I convert it to VB. NET.(I only have vb file not the project, I can not use the option file->open->convert in VB. NET).

Here is the code:

'CREATE CONNECTION OBJECT AND ASSIGN CONNECTION STRING

Dim conn As ADODB.Connection

Set conn = New ADODB.Connection

conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _

& "SERVER=deimos.iro.umontreal.ca;" _

& "DATABASE=chau;" _

& "UID=chau;" _

& "PWD=chau;" _

& "OPTION=" & 1 + 2 + 8 + 32 + 2048 + 16384

conn.CursorLocation = adUseClient

conn.Open

'CREATE TABLE FOR SAMPLE CODE

conn.execute "CREATE TABLE files(file_id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, file_name VARCHAR(64) NOT NULL, file_size MEDIUMINT UNSIGNED NOT NULL, file MEDIUMBLOB NOT NULL)"

'OPEN RECORDSET FOR WRITING

Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset

Dim mystream As ADODB.Stream

Set mystream = New ADODB.Stream

mystream.Type = adTypeBinary

rs.Open "SELECT * FROM files WHERE 1=0", conn, adOpenStatic, adLockOptimistic

rs.AddNew

mystream.Open

mystream.LoadFromFile "c:\myimage.gif"

rs!file_name = "myimage.gif"

rs!file_size = mystream.size

rs!file = mystream.read

rs.Update

mystream.Close

rs.Close

'OPEN RECORDSET TO READ BLOB

rs.Open "Select * from files WHERE files.file_id = 1", conn

mystream.Open

mystream.Write rs!File

mystream.SaveToFile "c:\newimage.gif", adSaveCreateOverWrite

mystream.close

rs.close

'OPEN RECORDSET FOR UPDATE OF BLOB COLUMN

rs.Open "Select * from files WHERE files.file_id = 1", conn, adOpenStatic, adLockOptimistic

mystream.Open

mystream.LoadFromFile "c:\updateimage.gif"

rs!file = mystream.Read

rs.Update

mystream.Close

rs.Close

'OPEN RECORDSET TO READ UPDATED IMAGE

rs.Open "Select * from files WHERE files.file_id = 1", conn

mystream.Open

mystream.Write rs!file

mystream.SaveToFile "c:\newupdatedimage.gif", adSaveCreateOverWrite

mystream.Close

rs.Close

conn.execute "DROP TABLE files"

conn.Close

msgbox "Success! Check your C:\ directory for newimage.gif and newupdatedimage.gif"

 

Schenz

Well-known member
Joined
Sep 11, 2004
Messages
181
Location
Cincinnati, OH
Programming Experience
5-10
I am hoping to have a sample tutorial in the next week or so on my website for using VB.NET, mySQL, and the new mySQL .NET Connector.

I will post the link when it is ready.
 
Top Bottom