我下载了一些示例代码,其中包含标记代码中的数据库查询。它对数据库进行查询并显示Web表单的结果,我想将输出转移到文本文件,我不知道如何做到这一点? 这可以从这里完成,还是更容易在源代码中编码并建立与数据库的新连接?
示例代码:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringIP %>"
DeleteCommand="DELETE FROM [ip-to-country] WHERE [ID] = ?" InsertCommand="INSERT INTO [ip-to-country] ([ID], [BeginingIP], [EndingIP], [TwoCountryCode], [ThreeCountryCode], [CountryName]) VALUES (?, ?, ?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:ConnectionStringIP.ProviderName %>" SelectCommand="SELECT * FROM [ip-to-country] WHERE (([BeginingIP] <= ?) AND ([EndingIP] >= ?))"
UpdateCommand="UPDATE [ip-to-country] SET [BeginingIP] = ?, [EndingIP] = ?, [TwoCountryCode] = ?, [ThreeCountryCode] = ?, [CountryName] = ? WHERE [ID] = ?">
<SelectParameters>
<asp:ControlParameter ControlID="txtIPNumber" DefaultValue="" Name="BeginingIP" PropertyName="Text"
Type="Double" />
<asp:ControlParameter ControlID="txtIPNumber" DefaultValue="" Name="EndingIP" PropertyName="Text"
Type="Double" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="BeginingIP" Type="Double" />
<asp:Parameter Name="EndingIP" Type="Double" />
<asp:Parameter Name="TwoCountryCode" Type="String" />
<asp:Parameter Name="ThreeCountryCode" Type="String" />
<asp:Parameter Name="CountryName" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="BeginingIP" Type="Double" />
<asp:Parameter Name="EndingIP" Type="Double" />
<asp:Parameter Name="TwoCountryCode" Type="String" />
<asp:Parameter Name="ThreeCountryCode" Type="String" />
<asp:Parameter Name="CountryName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<br />
IP Address :
<asp:TextBox ID="txtIPAddress" runat="server" Wrap="False"></asp:TextBox>
<br />
IP Number :
<asp:TextBox ID="txtIPNumber" runat="server" AutoPostBack="True" ReadOnly="True"
Wrap="False"></asp:TextBox>
<br />
<br />
答案 0 :(得分:1)
你最好在后面的代码中执行此操作,对数据集或实体等进行数据库调用,对数据执行任何操作,然后使用相同的数据对象作为数据网格的源或转发器,或者您希望显示此数据。