错误:执行ExecuteNonQuery时,')'附近的语法不正确

时间:2015-03-24 12:30:22

标签: c# .net

我只想保存详细信息,但功能代码给出了错误帮助。我的代码是: -

    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 个答案:

答案 0 :(得分:4)

您遇到的问题是您的SQL不完整。 SQL插入语句应该是

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

您的代码中只有第一部分,即:

insert into <tablename> (col1, col2);

在占位符中添加参数,你应该没问题。