shinichi90
New member
- Joined
- Jun 12, 2011
- Messages
- 2
- Programming Experience
- 1-3
Hi!!
I'm having problems inserting data into mysql through vb.net.
I've done something similiar like this using IBM DB2 and vb.net 2008 and it works. Currently, I'm using vb.net 2010.
The connection to the database is fine I think because I was able to retrieve the table to be viewed in vb2010. Is the syntax somehow wrong?
Thank you.
Regards,
Shinichi90
I'm having problems inserting data into mysql through vb.net.
VB.NET:
Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Public Class Form2
Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
Me.Hide()
Form1.Show()
End Sub
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim conn As MySqlConnection = New MySqlConnection()
conn.ConnectionString = "Database=fyp;Data Source=localhost;User Id=root;Password=fyp"
Dim myCommand As New MySqlCommand
Dim sql As String
sql = "insert into mcq (Question,OptionA,OptionB,OptionC,OptionD) values ('" & questionObj.Text & "','" & optionA.Text & "','" & optionB.Text & "','" & optionC.Text & "','" & optionD.Text & "')"
conn.Open()
myCommand.Connection = conn
myCommand.CommandText = sql
conn.Close()
conn.Dispose()
End Sub
I've done something similiar like this using IBM DB2 and vb.net 2008 and it works. Currently, I'm using vb.net 2010.
The connection to the database is fine I think because I was able to retrieve the table to be viewed in vb2010. Is the syntax somehow wrong?
Thank you.
Regards,
Shinichi90