Stuck! 'Insert' problem with database

fr0s1y

Member
Joined
May 16, 2011
Messages
14
Programming Experience
1-3
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
 
perhaps putting parameters in your query would help simplify

Parameterized Query | All About .NET

SQL Server would be like
insert into tblApps (colx, coly, colz) values (@x, @y, @z)

looks like mysql (based on that article i pasted) uses ?[value]

i would try that, as i see "+" in your query string, which should be "&" in vb, if i'm reading that right after pasting it into vb .net.
 

Latest posts

Back
Top