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

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!!

Thanx dude... it worked !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.