Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

VB/JQuery webservice problem

Hi,

I've hit a bit of a problem with a jQuery and a webservice. The webservice is in VB.NET and it's been quite a while since I last did anything in VB or a webservice.

Thing is, I'm not sure if the problem is in the query or in the code. All I get when I run is a button (which is correct) and after I click it, I get an error 500 - which doesn't really help.

The query (below) has security issues which I'm completely aware of - but as it's for my own use, that's ok - I can tidy that up at some point if I decide to use it.

[code]



A quick and dirty hack


$(document).ready(function() {
$("#btnMore").click(function() {
$.ajax({
type:"POST",
contentType: "application/json; charset=utf-8",
url: "WebService1.asmx/GetData",
data: "{'localhost', 'paul', '', 'Database1', {'SELECT','Name','where','age > 25','and','hometown == Liverpool'}, {'','','',''}",
success: onSuccess,
error: onError
});
});
});

function onSuccess(result)
{
$("#datalist").empty()
var strings = result.d;
for (var i = 0; i < strings.length; ++i)
$("#datalist").append("" + strings[i] + "");
}

function onError(result)
{
alert(result.status + ": " + result.statusText);
}



[/code]

I have a feeling that it's down to what I'm passing into the webservice rather than the webservice

[code]
_
_
_
_
Public Class WebService1
Inherits System.Web.Services.WebService

_
Public Function GetData(ByVal server As String, ByVal uid As String, ByVal pw As String, _
ByVal db As String, ByVal cmds As ArrayList, ByVal tbl As ArrayList) As DataSet
Dim connection As SqlConnection
Dim data As New DataSet("GetData")
Dim constr As String = "server=" + server + "; uid=" + uid + "; pwd=" + pw + "; database=" + db
Try
connection = New SqlConnection(constr)
connection.Open()
For i = 0 To cmds.Count
If (Not (cmds(i).ToString()).StartsWith(("SELECT" Or "Select"))) Then
Throw MySQLException("The SQL command must start with SELECT or Select")
End If
Dim command As New SqlCommand
command.Connection = connection
command.CommandText = cmds(i).ToString()
Dim dataadapter As New SqlDataAdapter
dataadapter.SelectCommand = command
dataadapter.TableMappings.Add("Table", tbl(i).ToString())
dataadapter.Fill(data)
Return data
Next

Catch ex As System.Data.SqlClient.SqlException
Throw
End Try
connection.Close()
End Function

Private Function MySQLException(ByVal p1 As String) As Exception
Throw New NotImplementedException
End Function

End Class[/code]

I'm using VS2010 and if I set a debug point in the VB webservice, it comes up with a webpage which gives me the method but the error is odd - it's saying the parameters needed have to be primitives rather than generics. I know I can pass generics into a webservice in C#, so I'm wondering if this is a VB problem more than anything.

The database has been set up in VS2010, so I'm assuming it's an mssql one so the connection code should be right (though the connection string may not be - the database is called Database1 and I'm using Table1 - do I pass Database1 or Table1 in via the jQuery?)

Any help, advice or pointers in the right direction on this would be appreciated. It's been ages since I've done any webservices and possibly longer since doing anything in anger with VB.NET!

Paul

P.S. I originally posted this on the webserver forum... sorry...
Sign In or Register to comment.