Foros del Web » Programación para mayores de 30 ;) » .NET »

problemas con archivos .csv

Estas en el tema de problemas con archivos .csv en el foro de .NET en Foros del Web. Hola tengo un problema tengo una hoja en excel llena de datos y la inserto en una tabla de sql de la siguiente manera. Dim ...
  #1 (permalink)  
Antiguo 02/03/2006, 17:04
 
Fecha de Ingreso: septiembre-2005
Mensajes: 26
Antigüedad: 18 años, 8 meses
Puntos: 0
problemas con archivos .csv

Hola tengo un problema tengo una hoja en excel llena de datos y la inserto en una tabla de sql de la siguiente manera.

Dim x As String
Try

Dim openFileDialog1 As New OpenFileDialog
Try
openFileDialog1.Filter = "Archivos de Texto|*.csv"
openFileDialog1.Title = "Seleccionar un archivo de Texto"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
If openFileDialog1.FileName <> "" Then

Try
x = openFileDialog1.FileName.Substring(openFileDialog1 .FileName.LastIndexOf("\"))
Dim y As Integer
longitud = x.Length
longitud = longitud - longitud + 2
firstword = Mid(x, longitud, x.Length)
Catch ex As Exception
End Try
End If
End If

Catch ex As Exception
MsgBox(ex.Message)
End Try
Dim dire As String = openFileDialog1.FileName
Dim excelConnection As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("provider=Micros oft.Jet.OLEDB.4.0; " & "data source='" & dire.ToString & "'; " & "Extended Properties=Excel 8.0;")
excelConnection.Open()
firstword = Mid(x, longitud, x.Length - 5)
Dim MyCommand = New System.Data.OleDb.OleDbDataAdapter("INSERT INTO [ODBC; Driver={SQL Server};Server=(local);Database=Cydsadb;Trusted_Co nnection=yes].[DESCRU2004CORT] SELECT * FROM [" & firstword.Trim + "$" & "];", excelConnection)
MyCommand.TableMappings.Add("Table", "ExcelTest")
Dim DS = New System.Data.DataSet
MyCommand.Fill(DS)
Me.datagrid1.DataSource = DS.Tables(0).DefaultView
Catch ex As Exception
MsgBox(ex.Message)
End Try

el problema es cuando trato de hacer lo mismo con archivos .csv, si me los lee y los pasa a un datagrid pero no puedo hacer que me los guarde...me marca el siguiente error...Syntaxix error in INSERT INTO statement

lo hago de la siguiente manera

Try
Dim cnx As OdbcConnection
Dim cn As SqlConnection
Dim dt As New DataTable
Dim da As New OdbcDataAdapter
Dim cmd As OdbcCommand
Dim pTest As OdbcParameter
Dim cnxStr As String
Dim CSVFolder As String
Dim CSVFileName As String
CSVFolder = "C:\"
CSVFileName = "DESCRU2004CORT.csv"
cnxStr = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + CSVFolder + ";"
cnx = New OdbcConnection(cnxStr)

cmd = New OdbcCommand("INSERT INTO [ODBC; Driver={SQL Server};Server=(local);Database=Cydsadb;Trusted_Co nnection=yes].[DESCRU2004CORT] SELECT * FROM [DESCRU2004CORT.csv];", cnx)
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
cnx.Open()
da.Fill(dt)

Me.datagrid1.DataSource = dt
' Me.datagrid1.DataBind()

Catch ex As Exception
MsgBox(ex.Message)
End Try

alguna idea ????
  #2 (permalink)  
Antiguo 02/03/2006, 20:20
Avatar de Mickel  
Fecha de Ingreso: mayo-2002
Ubicación: Lima, Peru
Mensajes: 4.619
Antigüedad: 22 años
Puntos: 7
no tendrias que haber hecho cnx.open antes de la llamada a cmd?
__________________
No tengo firma ahora... :(
  #3 (permalink)  
Antiguo 02/03/2006, 21:08
 
Fecha de Ingreso: septiembre-2005
Mensajes: 26
Antigüedad: 18 años, 8 meses
Puntos: 0
Hammm

si debi, pero ese no es el error, ya arregle el pequeño error de acomodo logico, pero sigue sin funcionar...alguna otra idea?
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:39.