Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlDataReader
Imports System.Data.SqlClient.SqlConnection


Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Inherits System.Windows.Forms.Form

    Dim myConnection As New SqlConnection
    Dim myCommand As New SqlCommand
    Dim ds As New DataSet
    Dim cmdtext As Integer
    Dim action As String
    Dim view As DataView
    Dim dr As SqlDataReader
        Dim cmdtext As String
        Dim cmd As New SqlCommand

        myConnection = New SqlConnection("Data Source=RUSHIKES-1A6789\SQLEXPRESS;Initial Catalog=AutoParts;Integrated Security=True")

Try
            myConnection.Open()
            myCommand.Connection = myConnection
            myCommand.CommandText = "Insert Into customer(c_id,c_name,c_add,c_phno1,c_phno2,c_phno3,c_email) values ("& txtb1.text",'"& txtb2.text"','"& txtb3.text"',"& txtb4.text","& txtb5.text","& txtb6.text",'"& txtb7.text"')"
            myCommand.ExecuteNonQuery()

        Catch ex As Exception
            MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
        Finally
            myConnection.Close()
        End Try

        fill()
        DataGridView1.Refresh()
End Sub
End Class

----------------------------------------------------------------------------------------
Code is throwing Error on Line :
End of Statement Expected

myCommand.CommandText = "Insert Into customer(c_id,c_name,c_add,c_phno1,c_phno2,c_phno3,c_email) values ("& txtb1.text",'"& txtb2.text"','"& txtb3.text"',"& txtb4.text","& txtb5.text","& txtb6.text",'"& txtb7.text"')"

----------------------------------------------------------------------------------------

Guys Please Help
Thanx in Advance

Edited 5 Years Ago by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

For number values -> "& text1.text &"
For string values -> '"& text1.text &"'
For date values -> #"& text1.text &"#
hope u have set data type for phone no. as number(double)


"Insert Into customer(c_id,c_name,c_add,c_phno1,c_phno2,c_phno3,c_email) values ('"& txtb1.text &"','"& txtb2.text &"','"& txtb3.text &"',"& txtb4.text &","& txtb5.text &","& txtb6.text &",'"& txtb7.text &"')"

good luck!!

This question has already been answered. Start a new discussion instead.