草庐IT

c# - 尝试实现主明细表时出错

coder 2023-10-24 原文

我试图实现如下所示的 Master Details 表,但出现错误提示

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

谁能帮我解决这个问题?

** 我认为他们是做类似事情的更好方法,所以如果是,请给我一个链接或告诉我我应该搜索什么? **

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoanReports.aspx.cs" Inherits="BankingDemo.LoanReports" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Banking Site (Demo)</title>
    <link href="StyleSheet.css" rel="stylesheet" />
</head>
<body>
    <form id="form" runat="server">
        <asp:GridView ID="GridView1" runat="server" HeaderStyle-BackColor="CornflowerBlue"  HeaderStyle-Font-Bold="true"  HeaderStyle-ForeColor="White"
             OnPageIndexChanging="GridView1_PageIndexChanging" DataKeyNames="LOAN_NUMBER" DataSourceID="QurClients" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
            AutoGenerateColumns="False" AllowPaging="True" PageSize="10"  AllowCustomPaging="False" AutoGenerateSelectButton="true"
             PagerSettings-Mode="Numeric" CellPadding="5" PagerSettings-PageButtonCount="5" SelectedRowStyle-CssClass="SelectedRow">
            <RowStyle VerticalAlign="Top" />
            <Columns>
                <asp:BoundField DataField="LOAN_NUMBER" HeaderText="LOAN NUMBER" ReadOnly="true" SortExpression="LOAN_NUMBER" />
                <asp:BoundField DataField="FIRST_NAME" HeaderText="First Name" ReadOnly="true" SortExpression="FIRST_NAME"  />
                <asp:BoundField DataField="FATHER_NAME" HeaderText="Father Name" ReadOnly="true" SortExpression="FATHER_NAME"  />
                <asp:BoundField DataField="FAMILY_NAME" HeaderText="Family Name" ReadOnly="true" SortExpression="FAMILY_NAME"  />
                <asp:BoundField DataField="MOTHER_NAME" HeaderText="Mother Name" ReadOnly="true" SortExpression="MOTHER_NAME"  />
                <asp:BoundField DataField="SEX" HeaderText="SEX" ReadOnly="true" SortExpression="SEX" />
                <asp:BoundField DataField="BIRTH_DATE" HeaderText="BIRTH_DATE" ReadOnly="true" SortExpression="BIRTH_DATE" />
                <asp:BoundField DataField="REG_PLACE_TEXT" HeaderText="Register Place" ReadOnly="true" SortExpression="REG_PLACE_TEXT" />
                <asp:BoundField DataField="PHONE" HeaderText="PHONE" ReadOnly="true" SortExpression="PHONE" />
                <asp:CommandField ShowSelectButton="true" SelectText="Details" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" DataKeyNames="LOAN_NUMBER" DataSourceID="QurLoans" Visible="false">
                            <Columns>
                                <asp:BoundField DataField="LOAN_NUMBER" HeaderText="Loan Number" Visible="false" ReadOnly="true" SortExpression="LOAN_NUMBER" />
                                <asp:BoundField DataField="AMOUNT" HeaderText="Amount" Visible="false" ReadOnly="true" SortExpression="AMOUNT" />
                                <asp:BoundField DataField="LOAN_INTEREST" HeaderText="Loan Interset" Visible="false" ReadOnly="true" SortExpression="LOAN_INTEREST" />
                                <asp:BoundField DataField="INTEREST_PERCENT" HeaderText="Interset Percent" Visible="false" ReadOnly="true" SortExpression="INTEREST_PERCENT" />
                                <asp:BoundField DataField="INSTALLMENT_AMOUNT" HeaderText="Instalment Amount" Visible="false" ReadOnly="true" SortExpression="INSTALLMENT_AMOUNT" />
                            </Columns>
                        </asp:GridView>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="QurClients" runat="server" ConnectionString="<%$ ConnectionStrings:ConnConfig %>" SelectCommand="select LOAN_NUMBER,FIRST_NAME,FATHER_NAME,FAMILY_NAME,MOTHER_NAME,SEX,BIRTH_DATE,REG_PLACE_TEXT,address_text,PHONE,profession_text,Notes FROM WORLD.LN_CLIENTS"></asp:SqlDataSource>
        <asp:SqlDataSource ID="QurLoans" runat="server" ConnectionString="<%$ ConnectionStrings:ConnConfig %>" SelectCommand="select LOAN_NUMBER,AMOUNT,LOAN_INTEREST,INTEREST_PERCENT,INSTALLMENT_AMOUNT from ln_loans" >
            <SelectParameters>
                <asp:Parameter Name="LOAN_NUMBER" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <br />
        <div><asp:Button ID="Toxls" runat="server" Text="Export to Excel" OnClick="Toxls_Click" /></div>
    </form>
</body>
</html>

这也是 GridView1_SelectedIndexChanged

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (GridViewRow row in GridView1.Rows)
    {
        row.FindControl("GridView2").Visible = false;
    }
    QurLoans.SelectParameters[0].DefaultValue = GridView1.SelectedDataKey[0].ToString();
    GridView1.SelectedRow.FindControl("GridView2").Visible = true;
}

下面的web.config文件

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>
  <connectionStrings>
    <add name="ConnConfig" connectionString="Server=localhost;Database=Mysql;User Id=root;Password=system;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

堆栈跟踪:

[Win32Exception (0x80004005): The system cannot find the file specified]

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
   System.Data.SqlClient.SqlConnection.Open() +96
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +120
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +136
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +86
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1494
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +22
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.GridView.DataBind() +9
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +114
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75
   System.Web.UI.Control.EnsureChildControls() +92
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Control.PreRenderRecursiveInternal() +160
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +883

最佳答案

添加

ProviderName="<%$ ConnectionStrings:ConnConfig.ProviderName %>"

到您的asp:SqlDataSource

您必须这样做,因为 SqlDataSource 假定您使用的是标准 SQL 服务器,并且由于您正在尝试连接到 MySql,因此您必须告诉它使用来自您的连接的提供程序名称字符串。

关于c# - 尝试实现主明细表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017417/

有关c# - 尝试实现主明细表时出错的更多相关文章

  1. ruby - ECONNRESET (Whois::ConnectionError) - 尝试在 Ruby 中查询 Whois 时出错 - 2

    我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.

  2. ruby - 在 64 位 Snow Leopard 上使用 rvm、postgres 9.0、ruby 1.9.2-p136 安装 pg gem 时出现问题 - 2

    我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po

  3. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  4. 使用 ACL 调用 upload_file 时出现 Ruby S3 "Access Denied"错误 - 2

    我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file

  5. ruby-on-rails - 每次我尝试部署时,我都会得到 - (gcloud.preview.app.deploy) 错误响应 : [4] DEADLINE_EXCEEDED - 2

    我是Google云的新手,我正在尝试对其进行首次部署。我的第一个部署是RubyonRails项目。我基本上是在关注thisguideinthegoogleclouddocumentation.唯一的区别是我使用的是我自己的项目,而不是他们提供的“helloworld”项目。这是我的app.yaml文件runtime:customvm:trueentrypoint:bundleexecrackup-p8080-Eproductionconfig.ruresources:cpu:0.5memory_gb:1.3disk_size_gb:10当我转到我的项目目录并运行gcloudprevie

  6. c# - 如何在 ruby​​ 中调用 C# dll? - 2

    如何在ruby​​中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL

  7. C# 到 Ruby sha1 base64 编码 - 2

    我正在尝试在Ruby中复制Convert.ToBase64String()行为。这是我的C#代码:varsha1=newSHA1CryptoServiceProvider();varpasswordBytes=Encoding.UTF8.GetBytes("password");varpasswordHash=sha1.ComputeHash(passwordBytes);returnConvert.ToBase64String(passwordHash);//returns"W6ph5Mm5Pz8GgiULbPgzG37mj9g="当我在Ruby中尝试同样的事情时,我得到了相同sha

  8. 华为OD机试用Python实现 -【明明的随机数】 2023Q1A - 2

    华为OD机试题本篇题目:明明的随机数题目输入描述输出描述:示例1输入输出说明代码编写思路最近更新的博客华为od2023|什么是华为od,od薪资待遇,od机试题清单华为OD机试真题大全,用Python解华为机试题|机试宝典【华为OD机试】全流程解析+经验分享,题型分享,防作弊指南华为o

  9. 基于C#实现简易绘图工具【100010177】 - 2

    C#实现简易绘图工具一.引言实验目的:通过制作窗体应用程序(C#画图软件),熟悉基本的窗体设计过程以及控件设计,事件处理等,熟悉使用C#的winform窗体进行绘图的基本步骤,对于面向对象编程有更加深刻的体会.Tutorial任务设计一个具有基本功能的画图软件**·包括简单的新建文件,保存,重新绘图等功能**·实现一些基本图形的绘制,包括铅笔和基本形状等,学习橡皮工具的创建**·设计一个合理舒适的UI界面**注明:你可能需要先了解一些关于winform窗体应用程序绘图的基本知识,以及关于GDI+类和结构的知识二.实验环境Windows系统下的visualstudio2017C#窗体应用程序三.

  10. ruby - 使用 postgres.app 在 rvm 下要求 pg 时出错 - 2

    我正在使用Postgres.app在OSX(10.8.3)上。我已经修改了我的PATH,以便应用程序的bin文件夹位于所有其他文件夹之前。Rammy:~phrogz$whichpg_config/Applications/Postgres.app/Contents/MacOS/bin/pg_config我已经安装了rvm并且可以毫无错误地安装pggem,但是当我需要它时我得到一个错误:Rammy:~phrogz$gem-v1.8.25Rammy:~phrogz$geminstallpgFetching:pg-0.15.1.gem(100%)Buildingnativeextension

随机推荐