将数据库数据导出到文本文件

编程入门 行业动态 更新时间:2024-10-27 03:37:58
本文介绍了将数据库数据导出到文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这有点奇怪,我已经剥去了它的熊骨头的代码,但它仍然没有像以前那样做...也许我看不到树木的树林,但是我看不到我做错了什么-:基本上,我是从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.

更多推荐

将数据库数据导出到文本文件

本文发布于:2023-07-09 00:20:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082127.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   数据库   导出到   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!