【问题标题】:DataSource error: UllReferenceExeption was unhandled by user code数据源错误:用户代码未处理 UllReferenceExeption
【发布时间】:2023-03-30 01:49:02
【问题描述】:

我的 GridView 表到数据库最初存在数据库问题,但我已更正它。

我面临的主要问题是,无论我使用<td> Classified Ads </td> 链接还是按钮,当我单击它时,Visual Studio 中的代码仍然会启动,而不管它都在代码中@ 987654323@.

我认为我的问题是无论我何时单击链接都会加载页面。我知道这一点,因为当我调试它并单击链接时,Visual Studio 代码仍然运行。

我该如何解决这个问题?

链接在哪里(文字显示:分类广告):

<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

【问题讨论】:

  • 不要使用 href = user onclick 属性并捕获事件
  • 不知道你所说的“赶上活动”是什么意思

标签: asp.net visual-studio-2010 datasource


【解决方案1】:

我猜我是如何修复它的(不确定这个过程会被称为什么),但我需要修复按钮链接版本的 Response.Redirect。

也就是说,我对 PostBackUrl 进行了编辑的按钮的属性:

对于 VB 代码,我添加了“True”部分:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-28
    • 2014-10-18
    相关资源
    最近更新 更多