本文介绍了将数据库数据导出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这有点奇怪,我已经剥去了它的熊骨头的代码,但它仍然没有像以前那样做...也许我看不到树木的树林,但是我看不到我做错了什么-:基本上,我是从SQL Server调出数据-通过循环将其拉出,在此示例中仅在mdb文件中进行处理...我创建了一个按钮,当按下该按钮时,该按钮会将数据导出到* .txt文件=不再执行此操作,它创建txt文件,但不添加数据,任何想法?
This is kinda weird, I have stripped the code to it''s bear bones and still it''s not doing what it used to do... maybe I cant see the woods for the tree, but I cant see what I have done wrong - : Basically, I am calling out data from a SQL server - pulling it through a loop, in this example just doing it on an mdb file... I created a button that when pressed it exported the data to a *.txt file = doesn''t do that anymore, it creates the txt file, but doesn''t append the data, any thoughts???
<pre lang="xml"><%@ Page Language=VB Debug=true %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.OLEDB" %> <script runat=server Language=VB > 'Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs) Dim intBtnClkCount As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeButton.Click intBtnClkCount += 1 ' writeButton.Visible = False End Sub Sub objWriter(ByVal s As Object, ByVal e As EventArgs) Dim FILE_NAME As String = "C:\Users\Fe\Desktop\xml\test.f" Dim DBConn As OleDbConnection Dim DBCommand As OleDbDataAdapter Dim DSPageData As New DataSet Dim I As Long DBConn = New OleDbConnection( _ "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _ & "DATA SOURCE=" _ & Server.MapPath("storage1.mdb;")) DBCommand = New OleDbDataAdapter _ ("Select * from samplesource", DBConn) DBCommand.Fill(DSPageData, _ "samplesource") For I = 0 To DSPageData.Tables("samplesource").Rows.Count - 1 Dim objWriter As New System.IO.StreamWriter(FILE_NAME) lblMessage.Text = lblMessage.Text _ & "<BR>Processed Record: " _ & DSPageData.Tables("samplesource"). _ Rows(I).Item("s1") objWriter.Close() Next End Sub </SCRIPT> <HTML> <HEAD> <TITLE></TITLE> </HEAD> <Body LEFTMARGIN="40"> <form id="Form1" runat="server"> <BR><BR> <asp:label id="lblMessage" runat="Server"/><asp:Button ID="writeButton" Text="Write" runat="server" OnClick="objWriter" /> </form> </BODY> </HTML>推荐答案
您已经创建了StreamWriter class的对象. 但是,您需要使用Write()或WriteLine()方法对其进行写入. 您只是在将文本写到标签-lblMessage.Text. You have create an object of the StreamWriter class. However, you need to write to it using the Write() or WriteLine() method. You are simply writing text to a label - lblMessage.Text.
更多推荐
将数据库数据导出到文本文件
发布评论