请问你在web.config中appsetting节点里面"NorthwindConnection"的数据库连接有没有

解决方案 »

  1.   

    web.config中应该有类似这样的节点
        <AppSettings>
            <add key="NorthwindConnection" value="............." />
        </appSettings>
    是用来设置整个站点的数据库连接的,你写了没有
      

  2.   

    web.confi 在哪里呀?不知道怎么设,请指教。
      

  3.   

    在你这个aspx文件的同一个文件夹里面。
    找到web.config文件,看到第一行是<?xml version="1.0" encoding="utf-8" ?>
    第二行是<configuration>,如果你没有看到刚才我提到的那个节点,那么你在第三行把 <AppSettings>
            <add key="NorthwindConnection" value="Server=Localhost;Trusted_Connection=True;database=数据库名" />
        </AppSettings>
    添加进去,其中"数据库名"换成你自己的数据库名就行了。如果有这个节点就替换。
      

  4.   

    谢谢,的确没有这三行,但是在<Configuration>下面加了之后,出错:
       <AppSettings>
           <add key="NorthwindConnection" value="Server=Localhost;Trusted_Connection=True;database=Northwind" />
       </AppSettings>报错 Error while trying to run project: Unable to start debugging on the web server......
    Verify there are no syntax errors in web.config by doing a Debug.
      

  5.   

    哦,忘了,是大小写敏感的,把<AppSettings>和</AppSettings>换成<appsettings>和</appsettings>
      

  6.   

    又写错了,是<appSettings>和</appSettings>注意大小写
      

  7.   

    改过来可以运行了,但是新的错误:
    Login failed for user 'LZHANG\ASPNET'. Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'LZHANG\ASPNET'.我在那行加了 ID 和 Password, 还是那样。<add key="NorthwindConnection" value="Server=Localhost;User ID=sa;Password=;Trusted_Connection=True;database=Northwind" />
      

  8.   

    嗨,终于出来了!!
    设:
     Trusted_Connection=False但是不能翻页,也不能排序。能再帮助看看吗?html 的全部 code:(DGPageSort.aspx 的程序在楼顶。)<%@ Page Language="vb" Src="DGPageSort.aspx.vb" Inherits="DGPageSort"%>
    <html>
    <head>
    <title>Paging and Sorting in a DataGrid</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body>
    <h3><font face="Verdana">Paging and Sorting in a DataGrid</font></h3>
    <form ID="form1" runat="server">
    <asp:Label id="lblOrderBy" runat="server" Visible="False" />
    <asp:DataGrid id="dtgCusts"
                  Width="700"
                  Cellpadding="2"
                  Cellspacing="0"
                  Gridlines="Horizontal"
                  HeaderStyle-BackColor="IndianRed" 
                  HeaderStyle-Font-Bold="True" 
                  HeaderStyle-Font-Name="Verdana" 
                  HeaderStyle-Font-Size="12px" 
                  HeaderStyle-ForeColor="White" 
                  ItemStyle-BackColor="Gainsboro" 
                  ItemStyle-Font-Name="verdana" 
                  ItemStyle-Font-Size="12px" 
                  AllowPaging="True"
                  OnPageIndexChanged="PageIndexChanged_Click"
                  PageSize="10"
                  PagerStyle-Mode="NumericPages"
                  PagerStyle-Position="Top"
                  PagerStyle-HorizontalAlign="Center"
                  PagerStyle-CssClass="pageLinks"
                  AllowSorting="True"
                  OnSortCommand="SortCommand_Click"
                  runat="server" />
    </form>
    </body>
    </html>
      

  9.   

    真奇怪,第二次运行完全正常了。
    十分感谢“光光”的热心帮助。
    还有疑问:
    如果我将那个 select * from .... 改为 store procedure 是否很麻烦,
    因为我的表有 3 个,如果不改,这一行是否要增加表名:dtgCusts.DataSource = myDataSet.Tables("Customers")改为:
    dtgCusts.DataSource = myDataSet.Tables("Customers,Sales,Employees")再次感谢!
      

  10.   

    1。翻页和排序是要自己后台写代码的,具体你可以去http://dotnet.aspx.cc/ShowList.aspx?id=1看看。
    2。改成stored procedure一开始是有点麻烦,但是会带给你很多好处。
       你的datasource在stored procedure里面完全可以用联合查询来解决,类似
       select ...from Customers,Sales,Employees 来解决