Object reference not set to an instance of an object.

  • Thread starter sista via DotNetMonster.com
  • Start date
S

sista via DotNetMonster.com

Wonder why I always got tis error? :(
help....

here's my code in forgot.aspx.vb
------------------------------------------------------------------
Sub lookup_click(ByVal s As Object, ByVal e As EventArgs)
Dim email As String = Request.Form("email")
Dim p As New PartyHouse
Dim ds As DataSet
ds = p.getDetail("*", "member", "memail", email)

If ds Is Nothing Then
msg.Text = "<font color=red>Sorry, there is no user with email
address <b>" & _
email & "</b> found.<br>Click <a href='register2.aspx'>here</a>
to register.</font>"
Else
Dim msgMail As New MailMessage
msgMail.To = email
msgMail.From = "(e-mail address removed)"
msgMail.Subject = "Password look up - PartyHouse.com"

With ds.Tables("member").Rows(0)
msgMail.BodyFormat = MailFormat.Html
msgMail.Body = "<html><body><a
href='https://localhost/partyhouse/'><img src='img/logomask.gif'></a>" & _
"<p>Dear " & .Item("title") & " " & .Item("fname") & "
" & .Item("lname") & ",</p>" & _
"<p>Your password is <b>" & .Item("mpassword") & "</b>.
" & _
"<p>Please keep this information for future use.</p>" &
_
"<p><br><br> Administrator @ <a
href='https://localhost/partyhouse/'>PartyHouse.com</a></p>" & _
"</body></html>"
End With
SmtpMail.Send(msgMail)

Response.Redirect("lookedup.htm")
End If
End Sub
-----------------------------------------------------------------


Here's my code for Partyhouse class:
-----------------------------------------------------------------
Public Function getDetail(ByVal thing As String, ByVal table As String,
ByVal cond1 As String, ByVal val1 As String) As DataSet
oCon = New OleDbConnection( _
"Provider=sqloledb;" & _
"Data Source=ts04.comp.nus.edu.sg,1433;" & _
"Initial Catalog=cs3266_00;" & _
"User Id=lydiasun;" & _
"Password=u0201098")
Dim query As String
query = "select " & thing & " from " & table & " where " & cond1 &
"='" & val1 & "'"
Dim mycommand As New OleDbCommand(query, oCon)

oCon.Open()
Dim dr As OleDbDataReader
dr = mycommand.ExecuteReader(CommandBehavior.CloseConnection)

Dim ds As DataSet
If dr.HasRows = True Then
ds = ConvertDataReaderToDataSet(dr)
'this function is to convert data reader to dataset.
'it's correct i've tried it out.
Else
ds = Nothing
End If
oCon.Close()
Return ds
End Function
 
G

Guest

Hi,

First off not the smartest thing to post your database username,
password, and server. Dont understand why you are converting a datareader to
a dataset why not just read in the dataset to begin with. Add Imports
system.data.sqlclient to the top of the code file. I dont think your
convertdatareadertodataset made a datatable with the name of member. I think
that is the object not set to reference of an object error you are getting.

Public Function getDetail(ByVal thing As String, ByVal table As String,
ByVal cond1 As String, ByVal val1 As String) As DataSet
oCon = New SQLConnection( _
"Data Source=ts04.comp.nus.edu.sg,1433;" & _
"Initial Catalog=cs3266_00;" & _
"User Id=lydiasun;" & _
"Password=u0201098")
Dim query As String
query = "select " & thing & " from " & table & " where " & cond1 &
"='" & val1 & "'"
Dim mycommand As New sqlCommand(query, oCon)

oCon.Open()
Dim da As new sqlDataReader(mycommand)

Dim ds As DataSet

da.Fill(ds, "member")
Return ds
End Function

Change your this in the lookup_click procedure

If ds Is Nothing Then

to

If ds.Tables("member").Rows.Count < 1 Then

Hope this helps.

Ken
-----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top