Export da VB: da tabella access a file csv

domenica 06 marzo 2011 - 22.46
Tag Elenco Tags  VB.NET  |  .NET 1.0  |  .NET 1.1  |  .NET 2.0  |  .NET 3.0  |  .NET 3.5  |  .NET 4.0  |  Windows Vista  |  Windows XP  |  Visual Studio 2008  |  Access (.mdb)

wsaurim Profilo | Newbie

Ciao ragazzi,

ho provato ad esportare il contenuto di una tabella con questo metodo:

Try
Dim link As OleDbConnection
Dim cmdSelect As OleDbCommand
link = New OleDbConnection
link.ConnectionString = common.BuildConnectionString()
link.Open()

cmdSelect = link.CreateCommand()
cmdSelect.CommandText = "SELECT * INTO [Text;HDR=No;DATABASE=" & AppDomain.CurrentDomain.BaseDirectory & "\sync].[comuni.txt] FROM comuni order by comune asc"
cmdSelect.ExecuteNonQuery()
ProgressBar1.Value = 40
Label2.Text = "Esportazione comuni completata"
link.Close()
Catch thisExcept As Exception
LabelMessage.Text = "Errore nella sincronizzazione: " & thisExcept.Message.ToString
LabelMessage.ForeColor() = System.Drawing.Color.Red
Button1.Enabled = True
End Try


ma anche provando la sola query in access, mi dà sempre errore "il separatore di campo della specifica dei file di testo non corrisponde al separatore decimale...".

Dentro un altro forum ho trovato conferma che qualcuno ce l'ha fatta:

You can use the ExcecuteNonQuery method of the OleDbCommand Class with a SQL statement for import and export with a Microsoft Access database:
Export to Text from Access:
SELECT * INTO [Text;HDR=No;DATABASE=e:\My Documents\TextFiles].[td.txt] FROM Table_3

Qualche suggerimento?
Thx, Auri



---- mi rispondo da solo, magari torna utile a qualcuno....
---- al psto della lettura file usate il vostro datareader

Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic

Class Program

Public Shared Sub Main(ByVal args As String())

Dim mydocpath As String = _
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sb As New StringBuilder()

For Each txtName As String _
In Directory.EnumerateFiles(mydocpath, "*.txt")
Using sr As New StreamReader(txtName)
sb.AppendLine(txtName.ToString())
sb.AppendLine("= = = = = =")
sb.Append(sr.ReadToEnd())
sb.AppendLine()
sb.AppendLine()

End Using
Next

Using outfile As New StreamWriter(mydocpath & "\AllTxtFiles.txt")
outfile.Write(sb.ToString())
End Using
End Sub
End Class
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5