I have an ajax call to a vb function. The vb function fails because the dataTable the query alludes to CFG_QUERY_REPORT
does not exist in the database.
I want the error message from the catch
in vb to be returned to the 'error' of the ajax so that I can display that error to the user. The reason being that the error message in VB states precisely that the table does not exist in the database, whereas the error that is actually displayed to the user from here
error: function (a, b, c) {
alert("Ajax call to multiAjax failed: " + a);
}
does not tell the user the error is due to a table that doesn't exist. The ajax error message is useless.
How can I display the error message from the vb catch
to the user?
Thanks
ajax:
function multiAjax(funcName, queryName, onSuccess) {
var result = null;
$.ajax({
type: "POST",
url: "WebService1.asmx/" + funcName,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (Response) {
onSuccess(Response)
},
data: JSON.stringify({ "queryName": queryName }),
error: function (a, b, c) {
alert("Ajax call to multiAjax failed: " + a);
}
});
}
VB
Public Function getQueryNo()
Try
Dim queryNumberSql As String
Dim queryNo As Integer
Using dr As New DataReader(dif)
queryNumberSql =
"SELECT min(unused) AS unused
FROM (
SELECT MIN(t1.QUERY_NUMBER)+1 as unused
FROM CFG_QUERY_REPORT AS t1
WHERE NOT EXISTS (SELECT * FROM CFG_QUERY_REPORT AS t2 WHERE t2.QUERY_NUMBER = t1.QUERY_NUMBER+1)
UNION
-- Special case for missing the first row
SELECT 1
FROM CFG_QUERY_REPORT AS t1
WHERE NOT EXISTS (SELECT * FROM CFG_QUERY_REPORT WHERE QUERY_NUMBER = 1)
) AS subquery"
dr.ExecuteReader(queryNumberSql)
While dr.Read()
queryNo = Integer.Parse(dr("unused"))
End While
Return queryNo
End Using
Catch ex As Exception
Console.WriteLine($"Error trying to set query number: {ex}")
Return ex
End Try
End Function
No comments:
Post a Comment