DataSource error: UllReferenceExeption was unhandled by user code

22 views Asked by At

I originally had database issues with my GridView table to database but I have corrected it.

My major issue I have faced is the fact that regardless of whether I use my <td> Classified Ads </td> link or a button, when I click it the code in Visual Studio still initiates regarless of the fact that it is all inside the code If Not IsPostBack Then.

I think my issue is the fact that the page loads regardless when I click the link. I know this for fact because when I debug it and click on the link the Visual Studio code still runs.

How can I fix this issue? enter image description here

Where link is (Text that says: Classified Ads):

<table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td align="left" valign="middle" width="87%">


                        &nbsp;&nbsp;<a href="Index.aspx" style="text-decoration:none;" ><font color="000000" 
                        face="Verdana, Arial, Helvetica, sans-serif" size="2.7"><b>Classified Ads</b></font>
                               </a>

                        &nbsp;<font color="000000" face="Verdana, Arial, Helvetica, sans-serif" size="2.7" style="padding-top:5px">></font>&nbsp;

                        <a style="text-decoration:none;" href="WF_DisplayAll.aspx">
                        <font color="000000" face="Verdana, Arial, Helvetica, sans-serif" size="2.7"><b>All Classified Ads</b></font>
                        </a>

                     </td>

                     <td width="13%" valign="middle" align="right">
                            <a style="text-decoration:none;" href="Login.aspx">
                            <font color="000000" face="Verdana, Arial, Helvetica, sans-serif" size="2.7"> Admin&nbsp;&nbsp;&nbsp;&nbsp</font></a>
                     </td>
                </tr>
             </table>

Visual Studio:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    'OleDbDataAdapterSecurity.SelectCommand.CommandText = "SELECT Addate, username, Phonenbr, email, description FROM t_classifieds"


    'Dim OracleDataAdapterAds As OracleDataAdapter = New OracleDataAdapter
    'OracleDataAdapterAds.SelectCommand = strSelectAds

    ' Makes so it runs the first time
    If Not IsPostBack Then
        Dim conn As OleDbConnection = New OleDbConnection("Provider=""******"";user id=" & strUserID & ";data source=" & strDatabase & ";password=" & strPssWd)

        'Display All Classified Ads listed in the Database based on the following format/order
        'Date    Name    Home Phone Number     Description

        Dim ClassifiedStr As OleDbCommand = New OleDbCommand("SELECT classid, Addate, username, Phonenbr, email, description FROM t_classifieds", conn)
        Dim OracleDataAdapterAds As OleDbDataAdapter = New OleDbDataAdapter
        OracleDataAdapterAds.SelectCommand = ClassifiedStr
        Dim DsAds As DataSet = New DataSet
        DsAds.Clear()
        OracleDataAdapterAds.Fill(DsAds, "t_classifieds")
        DisplayAllClassifieds.DataSource = DsAds
        DisplayAllClassifieds.DataMember = "t_classifieds"
        DisplayAllClassifieds.DataBind()
    End If
End Sub
1

There are 1 answers

0
narue1992 On BEST ANSWER

I guess how I fixed it (which not sure what this process would be called is) but I needed to fix my Response.Redirect for the button link version.

In other words, the properties of the button I did an edit to the PostBackUrl:

enter image description here

And for the VB code I added the "True" part:

Protected Sub Main_Click(sender As Object, e As EventArgs) Handles Main.Click

    Response.Redirect("Index.aspx", True)
End Sub