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

Buen Día, les escribo porque la verdad he buscado y he desarmado el query como 20 veces y la verdad no entiendo el problema que tengo.

Tengo el siguiente codigo:
donde la primera parte se labre un libro en excel y se lee la hoja, luego realizo la consulta a toda la hoja y luego realizo el insert para cada columna en SQL
los .replaces es porque hay celdas que estan en blanco y las reemplazo por un guion (-) para que no me de error el insert.

Que es lo que me pasa... la hoja tiene 15736 filas el insert funciona perfecto, es decir inserta todas las filas del excel a la base de datos en SQL peo que pasa la columna Variable_Values (columna 32) tiene valor toda la columna y no me esta tomando eso valores y en vez de colocarme el valor que sale en la hoja de excel lo deja en blanco, ¿por que me pasa esto? Trabajo con SQL y Visual Studio

Si alguien puede ayudarme GRACIAS!!!

Código vb:
Ver original
  1. conexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & BuscarArchivo.FileName & " ; Extended Properties= Excel 8.0;"
  2.                         conexion.Open()
  3.                         Dim hoja As String = Strings.Left(BuscarArchivo.SafeFileName.ToString, 31)
  4.                         comando.CommandText = "SELECT * FROM [" & hoja & "$]"
  5.                         comando.Connection = conexion
  6.                         adaptador.SelectCommand = comando
  7.                         adaptador.Fill(ds)
  8.                         Form1.ProgressBar1.Minimum = 0
  9.                         Form1.ProgressBar1.Maximum = ds.Tables(0).Rows.Count - 1
  10.                         For Each f As DataRow In ds.Tables(0).Rows
  11.                             If filas < ds.Tables(0).Rows.Count - 1 Then
  12.  
  13.                                 Comm.CommandText = "INSERT INTO [NSO].[dbo].[Audited_Facts_regular]([Fecha_Carga],[CountryID],[ContryName],[StoreID],[NSO_StoreID],[StoreName] " & _
  14.                                                     " ,[StoreAddres] ,[StoreStatud],[StoreComments],[StoreStarDateTime],[StoreEndDateTime],[StoreClosing]" & _
  15.                                                     " ,[PlannetAudit],[AuditInstructionID],[SyneryMode],[IMDB_ProductID],[NSO_ProductID],[ProductName]" & _
  16.                                                     " ,[ProductCategory],[Barcode],[ProductLevel],[ProductComment],[LocationID],[LocationName],[LocationComments]" & _
  17.                                                     " ,[ExhibitionID],[ExhibitionName],[ExhibitionLevel],[ExhibitionPossition],[ExhibitionComment],[VariableID]" & _
  18.                                                     " ,[VariableName],[VariableAtribute],[VariableValue],[VariableComments],[FactType],[ReUser])" & _
  19.                                 "VALUES('" & String.Format("{0:dd-MM-yyyy}", DateTime.Now.Date) & "','" & f(0).ToString().Replace(" ", "-") & "','" & f(1).ToString().Replace(" ", "-") & "','" & f(2).ToString() & "','" & f(3).ToString() & "','" & f(4).ToString().Replace("'", "´") _
  20.                                         & "  ','" & f(5).ToString().Replace(" ", "-") & "','" & f(6).ToString().Replace(" ", "-") & "',' " & f(7).ToString().Replace(" ", "-") & "','" & f(8).ToString().Replace(" ", "-") _
  21.                                         & "  ','" & f(9).ToString().Replace(" ", "-") & "',' " & f(10).ToString().Replace(" ", "-") & "','" & f(11).ToString().Replace(" ", "-") & "','" & f(12).ToString().Replace(" ", "-") _
  22.                                         & "  ','" & f(13).ToString().Replace(" ", "-") & "','" & f(14).ToString().Replace(" ", "-") & "','" & f(15).ToString().Replace(" ", "-") & "','" & f(16).ToString().Replace(" ", "-") _
  23.                                         & "  ','" & f(17).ToString().Replace(" ", "-") & "','" & f(18).ToString().Replace(" ", "-") & "','" & f(19).ToString().Replace(" ", "-") & "',' " & f(20).ToString().Replace(" ", "-") _
  24.                                         & "  ','" & f(21).ToString().Replace(" ", "-") & "','" & f(22).ToString().Replace(" ", "-") & "','" & f(23).ToString().Replace(" ", "-") & "','" & f(24).ToString().Replace(" ", "-") _
  25.                                         & "  ','" & f(25).ToString().Replace(" ", "-") & "','" & f(26).ToString().Replace(" ", "-") & "','" & f(27).ToString().Replace(" ", "-") & "',' " & f(28).ToString().Replace(" ", "-") _
  26.                                         & "  ','" & f(29).ToString().Replace(" ", "-") & "','" & f(30).ToString().Replace(" ", "-") & "','" & f(31).ToString().Replace(" ", "'0'") & "','" & f(32).ToString().Replace(" ", "'0'") _
  27.                                         & "  ','" & f(33).ToString().Replace(" ", "-") & "','" & f(34).ToString().Replace(" ", "-") & "','NULL')"
  28.  
  29.                                 Comm.Connection = Cone
  30.                                 inserts = inserts + Comm.ExecuteNonQuery()
  31.                                 filas = filas + 1
  32.                                 Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
  33.                                 Application.DoEvents()
  34.                             End If
  35.                         Next