Hi,
Ive been working on this project for a while now and have been stuck with this problem for nigh on half a week and i'm beginning to feel fairly defeated.
I am building an application that contains a daily log of someones activities, nothing complicated. I have a form that contains a textbox (obv), a date picker, the logged in user id, the 'service users' id (who the log is about) and a submit button. All it needs to do is submit that info to the database.
I've never had a problem using mySql before, ive used it with PHP successfully however im new to VB and kind of need steering in the right direction, heres what i have after doing tons of reading,
Imports MySql.Data.MySqlClient
Public Class dailyLog
Dim mySQLConnectionString As String = My.Settings.mysqlconn
Dim mySqlConn As New MySqlConnection
Private Sub dailyLogExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogExitBtn.Click
Me.Close()
End Sub
Public ReadOnly Property GetMySqlConnectionString() As String
Get
Return (mySQLConnectionString)
End Get
End Property
Private Function connOpen(ByRef errorMessage As String) As Boolean
Try
mySqlConn = New MySqlConnection
mySqlConn.ConnectionString = mySQLConnectionString
mySqlConn.Open()
Return (True)
Catch exError As MySqlException
errorMessage = exError.Message
Return (False)
End Try
End Function
Private Sub dailyLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mySqlConn.ConnectionString = mySQLConnectionString
mySqlConn.Open()
Dim User As String
User = My.Settings.user
dailyLogCurrentUser.Text = User
End Sub
Private Sub dailyLogSubBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogSubBtn.Click
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim _date = dailyLogDate.Value()
Dim user = dailyLogCurrentUser.Text()
Dim notes = dailyLogTxt.Text()
Dim SQL As String
SQL = "INSERT INTO `daily_log`(_date, userID, serviceUserID, notes) VALUES (`" + _date + "` , '" + user + "', 'mrX', '" + notes + "');"
myCommand.Connection = mySqlConn
myCommand.CommandText = SQL
myAdapter.InsertCommand = myCommand
Try
mySqlConn.Open()
myCommand.()
mySqlConn.Close()
Catch ex As Exception
End Try
End Sub
Private Sub dailyLogGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogGroupBox.Enter
End Sub
End Class
quick apologies about the format of the code, i'm not sure how to post code snippets properly
Ive been working on this project for a while now and have been stuck with this problem for nigh on half a week and i'm beginning to feel fairly defeated.
I am building an application that contains a daily log of someones activities, nothing complicated. I have a form that contains a textbox (obv), a date picker, the logged in user id, the 'service users' id (who the log is about) and a submit button. All it needs to do is submit that info to the database.
I've never had a problem using mySql before, ive used it with PHP successfully however im new to VB and kind of need steering in the right direction, heres what i have after doing tons of reading,
Imports MySql.Data.MySqlClient
Public Class dailyLog
Dim mySQLConnectionString As String = My.Settings.mysqlconn
Dim mySqlConn As New MySqlConnection
Private Sub dailyLogExitBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogExitBtn.Click
Me.Close()
End Sub
Public ReadOnly Property GetMySqlConnectionString() As String
Get
Return (mySQLConnectionString)
End Get
End Property
Private Function connOpen(ByRef errorMessage As String) As Boolean
Try
mySqlConn = New MySqlConnection
mySqlConn.ConnectionString = mySQLConnectionString
mySqlConn.Open()
Return (True)
Catch exError As MySqlException
errorMessage = exError.Message
Return (False)
End Try
End Function
Private Sub dailyLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mySqlConn.ConnectionString = mySQLConnectionString
mySqlConn.Open()
Dim User As String
User = My.Settings.user
dailyLogCurrentUser.Text = User
End Sub
Private Sub dailyLogSubBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogSubBtn.Click
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim _date = dailyLogDate.Value()
Dim user = dailyLogCurrentUser.Text()
Dim notes = dailyLogTxt.Text()
Dim SQL As String
SQL = "INSERT INTO `daily_log`(_date, userID, serviceUserID, notes) VALUES (`" + _date + "` , '" + user + "', 'mrX', '" + notes + "');"
myCommand.Connection = mySqlConn
myCommand.CommandText = SQL
myAdapter.InsertCommand = myCommand
Try
mySqlConn.Open()
myCommand.()
mySqlConn.Close()
Catch ex As Exception
End Try
End Sub
Private Sub dailyLogGroupBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dailyLogGroupBox.Enter
End Sub
End Class
quick apologies about the format of the code, i'm not sure how to post code snippets properly