If iva = 0 Then
connetionString = "Data Source=DESKTOP-LD02VBB;Initial Catalog=SIR;Persist Security Info=True;User ID=sa;Password=123"
firstSql = " Select cia = " + "'" + Cia.Text + "'" + ",suc = " + "'" + Suc.Text + "'" + ",dep = " + "'" + Dep.Text + "'" + ",tipos,folio,usuarioas400,Descripcion,proveedor1,FechaDoc = " + "'" + FechaDoc + "'" + ",id_prov_Hdz = " + "'" + Prov.Text + "'" + ",tipodemoneda " &
" ,Serie,Numero,GPO = " + "'" + gpototal.Text + "'" + ",CON = " + "'" + contotal.Text + "'" + ",CantidadD,UM,importeunitario,Importe = " + "'" + Imp.Text + "'" + ",estatusse,FolioSe,estatusdecarga,estatusdeaprobacion,Error,usuariodetransmision,pcqueenviadatos " &
",programa" &
",FechaCaptura = " + "'" + FechaCaptura + "'" + ",HoraCaptura = " + "'" + HoraCaptura + "'" + " " &
"From [SIR].[SIR].[SIR_60_REFERENCIAS] " &
" Left Join [dbo].[ClientesHerdez] As CH On [SIR].[SIR].[SIR_60_REFERENCIAS].nIdImex07 = CH.id_sclave_reco " &
"Left Join [SIR].[SIR].[SIR_188_FACTURAS_REFERENCIAS] As FAC On [SIR].[SIR].[SIR_60_REFERENCIAS].nIdReferencia60 = FAC.nIdReferencia60 " &
"Left Join [SIR].[SIR].[SIR_52_FACTURAS] As FA On FAC.nIdFactura52 = FA.nIdFactura52 " &
"Left Join [dbo].[Prov_Herdez]As PH On FA.nIdProveedor42 = PH.id_prov_reco " &
"LEFT JOIN [SIR].[Admin].[SIR_VT_Sabana_PedimentoMarcos] as SB ON [SIR].[SIR].[SIR_60_REFERENCIAS].nIdReferencia60 = SB.ID " &
" where [sReferencia] = " + "'" + TextBoxReferencia.Text + "'" + " "
secondSql = ""
connection = New SqlConnection(connetionString)
Try
connection.Open()
command = New SqlCommand(firstSql, connection)
adapter.SelectCommand = command
adapter.Fill(ds, "Table(0)")
adapter.Dispose()
command.Dispose()
connection.Close()
dt = ds.Tables(0)
For i = 0 To dt.Rows.Count - 1
MsgBox(dt.Rows(i).Item(0) & " -- " & dt.Rows(i).Item(1))
Next
Catch ex As Exception
'MsgBox("Can not open connection ! ")
End Try
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition", "attachment;filename=Herdez.csv")
Response.ContentType = "application/text"
Dim sb As New StringBuilder()
'For k As Integer = 0 To dt.Columns.Count - 1
'add separator
'sb.Append(dt.Columns(k).ColumnName + ","c)
'Next
'append new line
'sb.Append(vbCr & vbLf)
For i As Integer = 0 To dt.Rows.Count - 1
For k As Integer = 0 To dt.Columns.Count - 1
'add separator
sb.Append(dt.Rows(i)(k).ToString().Replace(",", ";") + ","c)
Next
'append new line
'sb.Append(vbCr & vbLf)
Next
Response.Output.Write(sb.ToString())
Response.Flush()
Response.End()
End If
Response.Output.Write(sb.ToString())
Response.Flush()
Response.End()
Catch ex As Exception
' MsgBox("Can not open connection ! ")
End Try
End If
If iva = 0 Then
Try
connetionString = "Data Source=DESKTOP-LD02VBB;Initial Catalog=SIR;Persist Security Info=True;User ID=sa;Password=123"
firstSql = " Select cia = " + "'" + Cia.Text + "'" + ",suc = " + "'" + Suc.Text + "'" + ",dep = " + "'" + Dep.Text + "'" + ",tipos,folio,usuarioas400,Descripcion,proveedor1,FechaDoc = " + "'" + FechaDoc + "'" + ",id_prov_Hdz = " + "'" + Prov.Text + "'" + ",tipodemoneda " &
" ,Serie,Numero,GPO = " + "'" + gpototal.Text + "'" + ",CON = " + "'" + contotal.Text + "'" + ",CantidadD,UM,importeunitario,Importe = " + "'" + Imp.Text + "'" + ",estatusse,FolioSe,estatusdecarga,estatusdeaprobacion,Error,usuariodetransmision,pcqueenviadatos " &
",programa" &
",FechaCaptura = " + "'" + FechaCaptura + "'" + ",HoraCaptura = " + "'" + HoraCaptura + "'" + " " &
"From [SIR].[SIR].[SIR_60_REFERENCIAS] " &
" Left Join [dbo].[ClientesHerdez] As CH On [SIR].[SIR].[SIR_60_REFERENCIAS].nIdImex07 = CH.id_sclave_reco " &
"Left Join [SIR].[SIR].[SIR_188_FACTURAS_REFERENCIAS] As FAC On [SIR].[SIR].[SIR_60_REFERENCIAS].nIdReferencia60 = FAC.nIdReferencia60 " &
"Left Join [SIR].[SIR].[SIR_52_FACTURAS] As FA On FAC.nIdFactura52 = FA.nIdFactura52 " &
"Left Join [dbo].[Prov_Herdez]As PH On FA.nIdProveedor42 = PH.id_prov_reco " &
"LEFT JOIN [SIR].[Admin].[SIR_VT_Sabana_PedimentoMarcos] as SB ON [SIR].[SIR].[SIR_60_REFERENCIAS].nIdReferencia60 = SB.ID " &
" where [sReferencia] = " + "'" + TextBoxReferencia.Text + "'" + " "
secondSql = ""
connection = New SqlConnection(connetionString)
connection.Open()
command = New SqlCommand(firstSql, connection)
adapter.SelectCommand = command
adapter.Fill(ds, "Table(0)")
adapter.Dispose()
command.Dispose()
connection.Close()
dt = ds.Tables(0)
For i = 0 To dt.Rows.Count - 1
MsgBox(dt.Rows(i).Item(0) & " -- " & dt.Rows(i).Item(1))
Next
Response.Clear()
Response.Buffer = True
Response.AddHeader("Content-Disposition", "attachment;filename=Herdez.csv")
Response.ContentType = "application/text"
Dim sb As New StringBuilder()
'For k As Integer = 0 To dt.Columns.Count - 1
'add separator
'sb.Append(dt.Columns(k).ColumnName + ","c)
'Next
'append new line
'sb.Append(vbCr & vbLf)
For i As Integer = 0 To dt.Rows.Count - 1
For k As Integer = 0 To dt.Columns.Count - 1
'add separator
sb.Append(dt.Rows(i)(k).ToString().Replace(",", ";") + ","c)
Next
'append new line
'sb.Append(vbCr & vbLf)
Next
Response.Output.Write(sb.ToString())
Response.Flush()
Response.End()
Catch ex As Exception
'MsgBox("Can not open connection ! ")
End Try
End If