尝试实现主详细信息表时出错

时间:2017-05-17 06:43:18

标签: c# mysql

我尝试实现Master Details表,如下所示,但我收到的错误是

  

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

任何人都可以帮我解决这个问题吗?

**并且我认为他们是更好的方式来做这样的事情所以如果是的话请给我一个链接或告诉我应该搜索什么? **

<%@ 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

1 个答案:

答案 0 :(得分:1)

添加

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

asp:SqlDataSource

您必须执行此操作,因为SqlDataSource假定您使用的是标准SQL服务器,并且由于您尝试连接到MySql,因此必须告诉它使用连接字符串中的提供程序名称。 / p>