0

i just want to save details, but the code of function is giving error pls help. the code i have is:-

    Dim con As New SqlConnection(Dal.conMain)
        Dim x As String = ""
        Try
            Dim str As String = "insert into company_master(unqid, jurisdiction, company_name, tag_line, Address_Line1, Address_Line2, Pan_No, STR_No)"
            Dim cmd As New SqlCommand(str, con)
            cmd.CommandType = CommandType.Text

            cmd.Parameters.AddWithValue("@jurisdiction", _jurisdiction)
            cmd.Parameters.AddWithValue("@company_name", _company_name)
            cmd.Parameters.AddWithValue("@tag_Line", _tag_Line)
            cmd.Parameters.AddWithValue("@Address_Line1", _Address_Line1)
            cmd.Parameters.AddWithValue("@Address_Line2", _Address_Line2)
            cmd.Parameters.AddWithValue("@Pan_No", _Pan_No)
            cmd.Parameters.AddWithValue("@str_No", _str_No)
            con.Open()
            x = cmd.ExecuteNonQuery().ToString()
            con.Close()
            If x = "" Or x = "0" Then
                Return False
            Else
                Return True
            End If
1
  • the error was "incorrect syntax near ')'". that encountered while executing executenonquery() Mar 24, 2015 at 12:35

1 Answer 1

4

The problem you have is that your SQL is incomplete. SQL insert statements should be

insert into <tablename> (col1, col2) values (@col1, @col2);

you only have the first part of that in your code, ie:

insert into <tablename> (col1, col2);

add in the placeholder for the parameters and you should be fine.

1
  • no problem. If this is the answer, please remember to mark it as such and if helpful please also press the ^ to mark it as useful Mar 24, 2015 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.