Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi there,

Can anyone help me out with this code I need a solution asap. I keep getting Object reference not set error when i compile it
txt1.Text = ds.Tables("Email").Rows(0).Item("Subject")
is where it seems to error! here is my code:

VB
Partial Public Class MaintainWEDAutoEmail
    Inherits System.Web.UI.Page

    Dim csccode As New CommonCode

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If User.Identity.IsAuthenticated Then
            If Session("Full_User_Name") = "" Then
                Session("User_Name") = User.Identity.Name
                Session("Full_User_Name") = csccode.FindUserFullName(Session("User_Name"))
            End If
            If Not Page.IsPostBack Then
                If User.IsInRole("maintain-wed-email-update") Or User.IsInRole("superuser") Then
                    btnMaintainUpdate.Visible = True
                Else
                    btnMaintainUpdate.Visible = False
                End If
                Dim ds As DataSet = New DataSet
                ds = csccode.GetWEDAutoEmail
                txt1.Text = ds.Tables("Email").Rows(0).Item("Subject")
                txt2.Text = ds.Tables("Email").Rows(0).Item("Body")
                txt3.Text = ds.Tables("Email").Rows(0).Item("Contact")
            End If
        Else
            Response.Redirect("Login.aspx")
        End If
    End Sub

    Protected Sub btnMaintainUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnMaintainUpdate.Click
        lblError.Text = ""
        Try
            lblError.Text = csccode.WEDAutoEmailUpdate(txt1.Text, txt2.Text, txt3.Text)
            If lblError.Text = "" Then
                lblError.Text = "WED Auto Email updated succesfully"
                csccode.Log(Session("Full_User_Name"), "WED Auto Email Update", "Email Update")
            Else
                lblError.Text = "** Problem updating WED Auto Email " & lblError.Text & " **"
            End If
        Catch ex As Exception
            lblError.Text = "** Problem updating WED Auto Email" & ex.Message & " **"
        End Try
    End Sub

End Class


Thanks in advance!
Posted

1 solution

Your code:
VB
ds = csccode.GetWEDAutoEmail
txt1.Text = ds.Tables("Email").Rows(0).Item("Subject")


The error means that something isn't there. The problem is likely one of these scenarios:
1. The GetWEDAutoEmail returned a dataset that was nothing
2. The dataset does not have a table named "Email"
3. The table "Email" does not have any rows
4. The table "Email" does not have a column named "Subject"

You will have to debug in order to figure out which. Place a break point on the line setting the text in txt1. When the breakpoint is hit, use quickwatch to narrow down which part is missing. You will either need to fix the GetWEAutoEmail or you will need to do checks before setting txt1.


*** UPDATE ***

How to use QuickWatch...well, google[^] has some articles on the topic...but glancing at them they don't have many nice screenshots. But maybe you'll want to look at them anyway. Basically when you've got your programming running and stopped at a breakpoint, you can highlight variables and see what their values are. So highlight just the ds in your line of code. At this point, you can probably see a popup that shows you more information and data that you've highlighted. You can use that popup, or you can right click and select QuickWatch from the menu. This pops up a menu where you can type in variables and bits of code and see what their values are. Since you had ds highlighted, ds should appear as the Expression that you are evaluating. If it has a value, you'll be able to see all of it's properties and thier values in the grid on the QuickWatch screen. If you can see that the ds has a value, then type in ds.Tables("Email") in the Expression textbox and press enter. Now you are checking to see if THAT has a value. Then type in ds.Tables("Email").Rows(0) to check for a value. Then tack on the .Item("Subject") and check that. It's kind of hard to explain, so you'll have to play with it a little bit to really get the hang of it. Hope this helps.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-May-12 11:42am    
Right, a 5.
--SA
Geofferz 9-May-12 12:01pm    
I have never used quickwatch before. Could you please briefly explain how to do this. Thanks Sorry I m new to this!
Kschuler 9-May-12 12:12pm    
I updated my solution with some info on QuickWatch.
Geofferz 9-May-12 12:36pm    
Kschuler Thank you so much for your help that worked!
Maciej Los 9-May-12 12:55pm    
Great! My 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900