I'm using Visual Basic 2008 Express. I want to make a small database editor, but I can't seem to gain access to the tables in my sql server. I seem to be connecting to the server ok, but I can't figure out how to access the tables so that I can edit the info there.
So far I have two forms, and a module where my global variables are declared.
Form1 is the login screen:
Code:
Imports MySql.Data.MySqlClient
Public Class Form1
Public Function GetConnectionInfo() As String
HostName = txtHost.Text
UserName = txtUsername.Text
PasswordName = txtPassword.Text
ConnectionName = TxtWorld.Text
Return ("Data Source=" + HostName + ";uid=" + UserName + ";pwd=" + PasswordName + ";database=" + ConnectionName + ";")
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Using conn As New MySqlConnection(GetConnectionInfo())
conn.Open()
If conn IsNot Nothing Then
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End If
End Using
'MessageBox.Show("Your credentials have been verified, transferring now!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
Catch sqlerror As MySqlException
MessageBox.Show(sqlerror.Message, "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
'Throw new Exception("An error occured while logging into the SQL server.", sqlerror);
End Try
FrmMain.Show()
Me.Hide()
End Sub
End Class
FrmMain is where the editing will take place:
Code:
Imports DAO
Public Class FrmMain
Private Sub FrmMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Form1.Close()
End Sub
Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ws As Workspace
Dim db As Database
Dim rs As Recordset
Dim strConnection As String
strConnection = "ODBC;DSN=" & ConnectionName & ";UID=" & UserName & ";PWD=" & PasswordName
ws = DBEngine.Workspaces(0)
db = ws.OpenDatabase("", False, False, strConnection)
rs = db.OpenRecordset("creature_loot_template")
End Sub
End Class
The line that says "ws = DBEngine.Workspaces(0)" is giving me an error message that says "Reference to a non-shared member requires an object reference."
Does anyone know how I can either fix this error, or can I connect to my sql server in a completely different (easier) way?