GERAR RELATORIO DADOS DATAGRIDVIEWER

ALTAIR148 18/04/2011 17:37:10
#371748
A seguinte função abaixo, carrega um datagridviewer via código, gostaria de gerar um relatório no crystal report com os dados dessa datagridviewer.

Dim Sql1 As String
Dim cmd As MySql.Data.MySqlClient.MySqlCommand
cmd = New MySql.Data.MySqlClient.MySqlCommand(Sql1, GetConexao2)
cmd.ExecuteNonQuery()


Dim Sql As String
For i = 0 To DataGridView1.Rows.Count - 1
Sql = [Ô]INSERT INTO tb_portadores(nome,bairro,endereco,cnpj)Values([ô][Ô] & _
DataGridView1.Item([Ô]Nome[Ô], i).Value & [Ô][ô],[ô][Ô] & _
DataGridView1.Item([Ô]Bairro[Ô], i).Value & [Ô][ô],[ô][Ô] & _
DataGridView1.Item([Ô]endereco[Ô], i).Value & [Ô][ô],[ô][Ô] & _
DataGridView1.Item([Ô]cnpj[Ô], i).Value & [Ô][ô])[Ô]
cmd = New MySql.Data.MySqlClient.MySqlCommand(Sql, GetConexao2)
cmd.ExecuteNonQuery()
Next



Obrigado

ALTAIR148 19/04/2011 08:39:02
#371802
alguem?
ALEXPASSOS 20/04/2011 00:19:46
#371958
Resposta escolhida
Olá

Eu criei esse rotina que varre o grid e preenche um dataset ai depois chamo o relatório.... funciona 100% comigo

      Application.DoEvents()
dSet.Tables([Ô]conscentrocustos[Ô]).Clear() [ô]Limpar o DataSet

frmImprimir.Crystal.Refresh()
frmImprimir.Crystal.RefreshReport()

vContador = DGView.Rows.Count

If vContador = 0 Then
MsgBox([Ô]Faça a consulta antes de imprimir[Ô], MsgBoxStyle.Information, [Ô]Atenção[Ô])
Exit Sub
End If

[ô]Variáveis com o nome das colunas
Dim vData As String
Dim vVencimento As String
Dim vCustos As String
Dim vConta As String
Dim vCliente As String
Dim vValor As String
Dim vStatus As String

Dim varLinhaList As Integer
Dim varLinha As Integer = 0
Dim varCol As Integer = 1 [ô]Começa a varrer o grid pela coluna
Dim contador As Integer = 0

varLinhaList = vContador * 8 [ô]Quantidade de colunas que o grid tem
contador += varLinhaList - 3

For i As Integer = 0 To varLinhaList

If varCol = 2 Then
vVencimento = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 3 Then
vCustos = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 4 Then
vConta = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 5 Then
vCliente = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 6 Then
vValor = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 7 Then
vStatus = DGView.Rows(varLinha).Cells(varCol).Value
End If

If varCol = 7 Then

Dim dr As Data.conscentrocustosRow = dSet.conscentrocustos.NewconscentrocustosRow
dr.consulta = vPeriodo
dr.data = vData
dr.vencimento = vVencimento
dr.custos = vCustos
dr.conta = vConta
dr.cliente = vCliente
dr.valor = FormatCurrency(vValor)
dr.status = vStatus
dr.pagar = maskPagar.Text
dr.pago = maskPago.Text
dr.receber = maskReceber.Text
dr.recebido = maskRecebido.Text

dSet.conscentrocustos.Rows.Add(dr)

varCol = 1
varLinha += 1

If varLinha = vContador Then Exit For

If i = contador Then Exit For
End If

If varCol = 1 Then
vData = DGView.Rows(varLinha).Cells(varCol).Value
End If
varCol += 1

Next i

Application.DoEvents()

Dim rptNormal As New relatCentroCustos
rptNormal.SetDataSource(dSet)
frmImprimir.MdiParent = frmPrincipal
frmImprimir.Show()
frmImprimir.Crystal.ReportSource = rptNormal


Tente ai... se não conseguir retorne.... caso resolva feche o tópico e dê a pontuação....

Agora vou dormi... a mulher já esta pertubando...rsrs
ALTAIR148 20/04/2011 07:55:00
#371967
Bom tentei implementar aqui mas não consegui, teria um simples exemplo só para que eu possa ver e adaptar no meu caso?

Obrigado
ALEXPASSOS 20/04/2011 13:07:02
#371997
Segue um exemplo
ALTAIR148 20/04/2011 14:05:15
#372013
Vlw Alex, agora sim consegui adaptar muito obrigado....
Tópico encerrado , respostas não são mais permitidas