bugtracker911
New member
- Joined
- Aug 26, 2006
- Messages
- 4
- Programming Experience
- Beginner
I'm in the process of creating a large app in VB.net and have designed all forms and database (mysql), just need to code everything together. I understand a lot of old VB, but I am finding .net tricky. Anyway, I am in the process of creating a data access layer for mysql, and need some feedback, as I have been unable to find any simple examples so I have created this myself, so its probably !?%£&, it seems to work but it doesn't seem right. Feedback will be apreciated...
HTML:
Imports MySql.Data.MySqlClient
Module modDatabase
Dim conn As MySqlConnection
Dim objData As DataTable
Dim objDa As MySqlDataAdapter
Dim objCb As MySqlCommandBuilder
Public Sub DB_Connect()
'check if connection exists
If Not conn Is Nothing Then conn.Close()
'connect to database
Dim connStr As String
connStr = String.Format("server=localhost;user id=root; password=; database=totalcontrol; pooling=false")
Try
conn = New MySqlConnection(connStr)
conn.Open()
Catch ex As MySqlException
MessageBox.Show("Error connecting to the server: " + ex.Message)
End Try
End Sub
Public Function DB_GetDataSet(ByVal sql)
objData = New DataTable
objDa = New MySqlDataAdapter(sql, conn)
objCb = New MySqlCommandBuilder(objDa)
objDa.Fill(objData)
Return objData
End Function
Public Function DB_Close()
objData.Dispose()
objDa.Dispose()
objCb.Dispose()
conn.Close()
conn.Dispose()
End Function
End Module