The problem is that your method is expecting an array of
DBClass
objects, but the calling code is only passing a single
DBClass
object.
Since you only ever use a single object in the method, the simplest solution is to change the method to accept a single object:
<WebMethod()> _
Public Sub DBAddClass(ByVal obj As DbClass)
Dim constr As String = ConfigurationManager.ConnectionStrings("myCon").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("INSERT INTO tab1 (Col1, Col2) VALUES (@Name, @Country)", con)
cmd.Parameters.AddWithValue("@Name", obj._col1)
cmd.Parameters.AddWithValue("@Country", obj._col2)
con.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
NB: An empty
Catch
block is a very bad idea. Only catch the specific exceptions which your code can handle, and log any exceptions which don't propagate to the caller.
If you want to pass an array of objects to the method, then you need to pass the correct JSON:
data: JSON.stringify({ obj: [ DbClass ] }),
(Note the extra square brackets around the
obj
value, indicating an array.)