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:
  1. Public Shared Function SearchDocuments(ByVal Query As String, ByVal SearchString As String) As Document()
  2.             Dim dtaLayer As New DataLayer
  3.             Dim htParameters As New Hashtable
  4.  
  5.             htParameters.Add("@searchString", SearchString)
  6.  
  7.             Dim dtaSet As DataSet = dtaLayer.ReturnParametisedDataSet(Query, htParameters)
  8.  
  9.             Dim objDocuments(dtaSet.Tables(0).Rows.Count - 1) As Document
  10.  
  11.  
  12.             For i As Integer = 0 To dtaSet.Tables(0).Rows.Count - 1
  13.                 Dim objDocument As New Document
  14.                 objDocument.DocumentCode = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_code"))
  15.                 objDocument.Title = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_title"))
  16.                 objDocument.Description = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_description"))
  17.                 objDocument.Category = Convert.ToString(dtaSet.Tables(0).Rows(i)("category_title"))
  18.                 objDocument.DateAdded = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_date_added"))
  19.                 objDocument.DateOfRevision = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_date_revision"))
  20.                 objDocument.DateLastRevised = Convert.ToDateTime(dtaSet.Tables(0).Rows(i)("document_last_revised"))
  21.                 objDocument.Author = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_author"))
  22.                 objDocument.Version = Convert.ToString(dtaSet.Tables(0).Rows(i)("document_version"))
  23.  
  24.                 objDocuments(i) = objDocument
  25.  
  26.             Next
  27.  
  28.  
  29.             Return objDocuments
  30.  
  31.         End Function

how do i stop it from breaking when no results are returned.

Thanks, Justin