I am trying to add record of entered inputs to data table but it's not working. I have tried this.
vb.net
Imports System.Data
Imports System.Configuration
Imports MySql.Data.MySqlClient
Partial Class index
Inherits System.Web.UI.Page
Dim con As New MySqlConnection("Data Source=204.11.58.166;port=3306;Initial Catalog=quistaBooking;User Id=my_username;password=my_password ;")
Protected Sub confirmBook_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles confirmBook.Click
Dim emailID, contactNo, source, destination, duration, distance, fare, datetime, vehicle As String
emailID = email.Text
contactNo = contact.Text
source = txtSource.Text
destination = txtDestination.Text
duration = dvDuration.Text
distance = dvDistance.Text
datetime = datetimepicker.Text
vehicle = selectVehicle.SelectedItem.ToString
Try
Dim str1 As String = "INSERT INTO logistics ('email', 'contact', 'source', 'destination', 'duration', 'distance', 'dateTime', 'vehicleType') values ('" + emailID + "', '" + contactNo + "', '" + source + "', '" + destination + "', '" + duration + "', '" + datetime + "', '" + vehicle + "')"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = str1
command.Connection = con
adapter.SelectCommand = command
data = command.ExecuteReader
con.Close()
Catch ex As Exception
Response.Write(ex)
End Try
End Sub
End Class
Error
System.InvalidOperationException: Connection must be valid and open. at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.CheckState() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at index.confirmBook_Click(Object sender, EventArgs e) in E:\MY WEB\Quista\Website\index.aspx.vb:line 58
Can any one help me where I am going wrong?
UPDATED ERROR
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''email', 'contact', 'source', 'destination', 'duration', 'distance', 'dateTime',' at line 1 at MySql.Data.MySqlClient.MySqlStream.ReadPacket() at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) at MySql.Data.MySqlClient.MySqlDataReader.NextResult() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at index.confirmBook_Click(Object sender, EventArgs e) in E:\MY WEB\Quista\Website\index.aspx.vb:line 59