when I try to insert values I got this error:
I Used this code

myConnection = New SqlConnection(connectionstring)
        myConnection.Open()

        Try

            Dim insert1 As SqlCommand = New SqlCommand("INSERT INTO [VBP].[dbo].[Return_Total] ([RGN0],[Date] ,[Totalamount],[User_Id],[C_NIC],[Comments],[Bill_No]) values ('" & Val(TextBox2.Text) & "','" & DateTimePicker1.Value.Date & "','" & TextBox4.Text & "','" & TextBox6.Text & "','" & TextBox3.Text & "','" & TextBox5.Text & "','" & Val(TextBox8.Text) & "'", myConnection)
            insert1.ExecuteNonQuery()
            insert1.Cancel()
            MessageBox.Show("New Data has Added")

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "ERROR")
        Finally
        End Try
        myConnection.Close()

the no is the no I'm giving.............

Recommended Answers

All 3 Replies

Just on the surface, it looks like you're missing a ")", this might work,

Dim insert1 As SqlCommand = New SqlCommand("INSERT INTO [VBP].[dbo].[Return_Total] ([RGN0],[Date] ,[Totalamount],[User_Id],[C_NIC],[Comments],[Bill_No]) values ('" & Val(TextBox2.Text) & "','" & DateTimePicker1.Value.Date & "','" & TextBox4.Text & "','" & TextBox6.Text & "','" & TextBox3.Text & "','" & TextBox5.Text & "','" & Val(TextBox8.Text) & "'"), myConnection)

Thank you.....................

you're welcome.

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.