This question is downvoted is because you can actually find plenty of example from the website.
Perhaps you do not know what keyword to search?
Try something like "dataset to textbox"?
or something here? Export a C# DataSet to a text file
Updated
I understand you may be new to vb. I will not give you the exact code but tell you what you can do.
First, declare a dataTable/dataset (I would prefer DataTable) to hold your query result from DB.
Dim dtresult As DataTable = 'Result from DB
Then loop through the datatable rows and get the data append into a string builder(or any other way you like to build your string)
Then append the string into the txt file.
This is something you can do.
UPDATE 2
Okay, something like this.
Private Sub DataTableToTXT()
Dim connetionString As String
Dim cnn As OleDbConnection
connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Scriptsdb.mdb;"
cnn = New OleDbConnection(connetionString)
Dim dtResult As New DataTable
cnn.Open()
'Change the query
Dim dataAdap As New OleDbDataAdapter("SELECT * FROM TABLE1", cnn)
dataAdap.Fill(dtResult)
cnn.Close()
'Change the path to your desired path
Dim exportPath As String = "C:Export"
Dim exportFileName As String = "data.txt"
If Not Directory.Exists(exportPath) Then
Directory.CreateDirectory(exportPath)
End If
Dim writer As New StreamWriter(exportPath + exportFileName)
Try
Dim sb As New StringBuilder
For Each row As DataRow In dtResult.Rows
sb = New StringBuilder
For Each col As DataColumn In dtResult.Columns
sb.Append(row(col.ColumnName))
Next
writer.WriteLine(sb.ToString())
Next
Catch ex As Exception
Throw ex
Finally
If Not writer Is Nothing Then writer.Close()
End Try
End Sub
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…