0

我是asp的新手,我用母版页创建了一个网格视图。但它在连接字符串中显示错误。谁能帮帮我?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
AutoGenerateEditButton="true" AutoGenerateDeleteButton="false" 
DataSourceID="SqlDataSource1" Font-Names="Arial" Font-Size="Smaller" DataKeyNames="Logid" > 
<columns>

          <asp:BoundField DataField="Logid" HeaderText="Logid" SortExpression="Logid" />
           <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
           <asp:BoundField DataField="PASSWORD" HeaderText="PASSWORD" SortExpression="PASSWORD" />

           <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />

           <asp:BoundField DataField="E_MAIL" HeaderText="E_MAIL" SortExpression="E_MAIL" />

</columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1"runat="server" ConnectionString="<%$ ConnectionString:SaqibConnectionString %>" 
SelectCommand="SELECT [Logid], [Username], [PASSWORD], [Time_Logged_in], [Time_Logged_Out], [Status], [Date_Logged_in], [E_MAIL]"
UpdateCommand="Update Log_Users SET Logid=@Logid, Username=@Username, PASSWORD=@PASSWORD, Status=@Status, E_mail=@E_mail"
DeleteCommand="DELETE FROM Log_Users WHERE Logid = @Logid">
<UpdateParameters>
                <asp:Parameter Name="Logid" />
                 <asp:Parameter Name="Username" />
                  <asp:Parameter Name="PASSWORD" />
                   <asp:Parameter Name="Status" />
                    <asp:Parameter Name="E_MAIL" />

</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
4

3 回答 3

0

你确定它不是像 ID="SqlDataSource1" 和 runat="server" 位之间的空格这样简单的东西。

这将导致错误“服务器标签格式不正确”错误。

于 2013-07-19T10:15:33.277 回答
0

连接字符串名称应该与您在 web 配置中给出的匹配,所以,

更改ConnectionString="<%$ ConnectionString:SaqibConnectionString %>"

ConnectionString="<%$ ConnectionStrings:db %>"

或将配置文件中的名称更改为您的连接字符串SaqibConnectionString

更新

 ConnectionString="<%$ ConnectionString:SaqibConnectionString %>"
                                      /\
                                you missed `s` here 

您在连接字符串设置上犯了错误,应该是ConnectionStrings,注意s最后

试试下面

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        SelectCommand="SELECT [Logid], [Username], [PASSWORD], [Time_Logged_in], [Time_Logged_Out], [Status], [Date_Logged_in], [E_MAIL] from Log_Users"
        UpdateCommand="Update Log_Users SET Logid=@Logid, Username=@Username, PASSWORD=@PASSWORD, Status=@Status, E_mail=@E_mail"
        DeleteCommand="DELETE FROM Log_Users WHERE Logid = @Logid" 
    ConnectionString="<%$ ConnectionStrings:db %>">
        <DeleteParameters>
            <asp:Parameter Name="Logid" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Logid" />
            <asp:Parameter Name="Username" />
            <asp:Parameter Name="PASSWORD" />
            <asp:Parameter Name="Status" />
            <asp:Parameter Name="E_MAIL" />
        </UpdateParameters>
    </asp:SqlDataSource>
于 2013-07-19T09:51:06.827 回答
0

如上所示,您的连接字符串名称是db,但您使用SaqibConnectionString的是连接字符串。所以使用ConnectionString="<%$ ConnectionString:db %>"代替 ConnectionString="<%$ ConnectionString:SaqibConnectionString %>"

更新1

并且您的选择语句不正确

SelectCommand="SELECT [Logid], [Username], [PASSWORD], [Time_Logged_in], [Time_Logged_Out], [Status], [Date_Logged_in], [E_MAIL]"

选择语句应该是 您的选择语句select [Logid], [Username], [PASSWORD], [Time_Logged_in], [Time_Logged_Out], [Status], [Date_Logged_in], [E_MAIL] from Log_Users中缺少的from tablename

更新2

ID="SqlDataSource1"和之间没有空间runat="server"

于 2013-07-19T09:54:14.010 回答