tlasher@dmacc.org
12/25/2002 10:27:00 PM
Since nobody seems to care or know about EOF - I'll post the answer
that I found. I think it's a kludge. So if anybody knows a better answer,
I'll all eyes.
The secret is in the Finally block:
Catch ex As Exception
Label16.Text = ex.ToString
Finally
da.Dispose()
If InStr(Label16.Text, "NullReference") > 0 Then
Label16.Text = "There are no events for that date."
'Label16.Text = SelCommand.ToString
parStartDat.Text = ""
'put all the other fields to null, also
End If
tlasher@dmacc.org (Terry Asher) wrote in message news:<671d2b79.0212132130.3c1307ad@posting.google.com>...
> I'm using a Select statement for a SQL database and using datasets.
> I have a DataRow line that gets the infamous:
> System.NullReferenceException error.
> Here is the pertinent code:
> Dim calds As New DataSet()
> Dim SelCommand, camp As String
> camp = "Newton"
> SelCommand = "Select * From events Where " & _
> "Campus = '" & camp & "'" & _
> " Order By EventName"
> Dim da As New SqlClient.SqlDataAdapter(SelCommand, SqlConnection1)
> Try
> da.Fill(calds, "events")
> Session("calds") = calds
>
> Dim row As DataRow
> Dim li As ListItem
> lboSelected.Items.Clear()
> For Each row In _
> calds.Tables("events").Rows()
> li = New ListItem( _
> text:=row("EventName").ToString(), _
> value:=row("CalID").ToString())
> lboSelected.Items.Add(li)
> Next
> lboSelected.SelectedIndex = 0
>
> Dim raaw As DataRow = calds.Tables("events").Select( _
> "CalID=" & lboSelected.SelectedItem.Value)(0)
> With raaw
> Campus.Text = .Item("Campus")
> Dept.Text = .Item("Dept")
> End With
> Label16.Text = String.Empty
> Catch ex As Exception
> Label16.Text = ex.ToString
> Finally
> da.Dispose()
> End Try
>
>
> There is No Newton in the Campus datafield, but I want the code to say if
> there is no Newton then Response.Redirect("noevents.asp").
> I've tried to say If raaw.IsNull, but the exception is thrown at
> the Dim raaw line and frankly I'm at a loss. In the old Asp I could
> say !EOF, but that doesn't work here.