[RESOLVED] when dataset executes stored proc..error
Hello all,
I currently have the below code, which is used to execute a data adapter fill method...
currently it executes a stored procedure. however, when no results are returns, it gives an error. the procedure doesnt need to give any results, as its a search function.
here is the code below.
VB Code:
Public Shared Function SearchDocuments(ByVal Query As String, ByVal SearchString As String) As Document()
Dim dtaLayer As New DataLayer
Dim htParameters As New Hashtable
htParameters.Add("@searchString", SearchString)
Dim dtaSet As DataSet = dtaLayer.ReturnParametisedDataSet(Query, htParameters)
Dim objDocuments(dtaSet.Tables(0).Rows.Count - 1) As Document
For i As Integer = 0 To dtaSet.Tables(0).Rows.Count - 1
Dim objDocument As New Document
objDocument.DocumentCode = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_code"))
objDocument.Title = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_title"))
objDocument.Description = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_description"))
objDocument.Category = Convert.ToString(dtaSet.Tables(0).Rows(i)("category_title"))
objDocument.DateAdded = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_date_added"))
objDocument.DateOfRevision = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_date_revision"))
objDocument.DateLastRevised = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_last_revised"))
objDocument.Author = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_author"))
objDocument.Version = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_version"))
objDocuments(i) = objDocument
Next
Return objDocuments
End Function
how do i stop it from breaking when no results are returned.
Thanks, Justin
Re: when dataset executes stored proc..error
Put it in a Try Catch block?
Re: when dataset executes stored proc..error
Quote:
Originally Posted by stanav
Put it in a Try Catch block?
well, it was, how ever it was just giving me the error. It was a index outside of bounds error. Sorry, i meant to say that the line that errors is the
VB Code:
Dim objDocuments(dtaSet.Tables(0).Rows.Count - 1) As Document
--EDIT
i have now got it working. needed to use a variable that would default to zero.
Thanks, Justin