Results 1 to 3 of 3

Thread: [RESOLVED] when dataset executes stored proc..error

  1. #1

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    Resolved [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:
    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

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: when dataset executes stored proc..error

    Put it in a Try Catch block?

  3. #3

    Thread Starter
    Addicted Member effekt26's Avatar
    Join Date
    Nov 2006
    Posts
    138

    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:
    1. 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
    Last edited by effekt26; Nov 19th, 2006 at 11:25 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width