Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/04/2013, 10:30
Avatar de yamiblancoc
yamiblancoc
 
Fecha de Ingreso: agosto-2011
Mensajes: 103
Antigüedad: 12 años, 8 meses
Puntos: 4
De acuerdo Respuesta: Problema en Insert

para quienes tienen problema con esto... lo que me paso fue que la fila es de tipo entero y lo necesitaba de tipo texto... pero como el archivo viene tipo .csv

lei el archivo de texto y luego lo almacene aqui les dejo como hacerlo

Código vb:
Ver original
  1. Dim fName As String = ""
  2.         BuscarArchivo.InitialDirectory = "Desktop"
  3.         BuscarArchivo.Filter = "CSV files (*.csv)|*.CSV"
  4.         BuscarArchivo.FilterIndex = 2
  5.         BuscarArchivo.RestoreDirectory = True
  6.                 If BuscarArchivo.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
  7.                 fName = BuscarArchivo.FileName
  8.                 '**** IMPORTAR DATOS CSV A DGV ****
  9.                Dim TextLine As String = ""
  10.                 Dim SplitLine() As String
  11.                 If System.IO.File.Exists(fName) = True Then
  12.                     Dim objReader As New System.IO.StreamReader(fName)
  13.                     Do While objReader.Peek() <> -1
  14.                         TextLine = objReader.ReadLine()
  15.                         SplitLine = Split(TextLine, ",")
  16.                         Me.DGVCarga.Rows.Add(SplitLine)
  17.                     Loop
  18.  
  19.                     '****  GUARDAR DATOS EN SQL  *******
  20.                    AbrirConexion()
  21.                  
  22.                     For Each f As DataGridViewRow In DGVCarga.Rows
  23.                         If filas < DGVCarga.Rows.Count - 1 Then
  24.                             Using Comm As New SqlCommand(sql, Cone)
  25.                                 Comm.CommandText = "INSERT INTO [NSO].[dbo].[Audited_Facts_regular]([CountryID],[ContryName],[StoreID],[NSO_StoreID],[StoreName] " & _
  26.                             " ,[StoreAddres] ,[StoreStatud],[StoreComments],[StoreStarDateTime],[StoreEndDateTime],[StoreClosing]" & _
  27.                                                         " ,[PlannetAudit],[AuditInstructionID],[SyneryMode],[IMDB_ProductID],[NSO_ProductID],[ProductName]" & _
  28.                                                         " ,[ProductCategory],[Barcode],[ProductLevel],[ProductComment],[LocationID],[LocationName],[LocationComments]" & _
  29.                                                         " ,[ExhibitionID],[ExhibitionName],[ExhibitionLevel],[ExhibitionPossition],[ExhibitionComment],[VariableID]" & _
  30.                                                         " ,[VariableName],[VariableAtribute],[VariableValue],[VariableComments],[FactType],[ReUser])" & _
  31.                                     "VALUES('" & f.Cells(0).Value.Replace(" ", "-") & "','" & f.Cells(1).Value.Replace(" ", "-") & "','" & f.Cells(2).Value & "','" & f.Cells(3).Value & "','" & f.Cells(4).Value.Replace("'", "´") _
  32.                                             & "  ','" & f.Cells(5).Value.Replace(" ", "-") & "','" & f.Cells(6).Value.Replace(" ", "-") & "',' " & f.Cells(7).Value.Replace(" ", "-") & "','" & f.Cells(8).Value.Replace(" ", "-") _
  33.                                             & "  ','" & f.Cells(9).Value.Replace(" ", "-") & "',' " & f.Cells(10).Value.Replace(" ", "-") & "','" & f.Cells(11).Value.Replace(" ", "-") & "','" & f.Cells(12).Value.Replace(" ", "-") _
  34.                                             & "  ','" & f.Cells(13).Value.Replace(" ", "-") & "','" & f.Cells(14).Value.Replace(" ", "-") & "','" & f.Cells(15).Value.Replace(" ", "-") & "','" & f.Cells(16).Value.Replace(" ", "-") _
  35.                                             & "  ','" & f.Cells(17).Value.Replace(" ", "-") & "','" & f.Cells(18).Value.Replace(" ", "-") & "','" & f.Cells(19).Value.Replace(" ", "-") & "',' " & f.Cells(20).Value.Replace(" ", "-") _
  36.                                             & "  ','" & f.Cells(21).Value.Replace(" ", "-") & "','" & f.Cells(22).Value.Replace(" ", "-") & "','" & f.Cells(23).Value.Replace(" ", "-") & "','" & f.Cells(24).Value.Replace(" ", "-") _
  37.                                             & "  ','" & f.Cells(25).Value.Replace(" ", "-") & "','" & f.Cells(26).Value.Replace(" ", "-") & "','" & f.Cells(27).Value.Replace(" ", "-") & "',' " & f.Cells(28).Value.Replace(" ", "-") _
  38.                                             & "  ','" & f.Cells(26).Value.Replace(" ", "-") & "','" & f.Cells(30).Value.Replace(" ", "-") & "','" & f.Cells(31).Value.Replace(" ", "0") & "','" & f.Cells(32).Value.Replace(" ", "0") _
  39.                                             & "  ','" & f.Cells(33).Value.Replace(" ", "-") & "','" & f.Cells(34).Value.Replace(" ", "-") & "','NULL')"
  40.                      
  41.                                 Comm.Connection = Cone
  42.                                 inserts = inserts + Comm.ExecuteNonQuery()
  43.                                 filas = filas + 1
  44.                              
  45.                             End Using
  46.                         End If
  47.                     Next
  48.                 End If
  49.             End If



FUNCIONA PERFECTAMENTE