Stampare immagini da Database Reportviewer?

martedì 07 giugno 2011 - 09.54
Tag Elenco Tags  VB.NET  |  .NET 4.0  |  Windows XP  |  Visual Studio 2010  |  SQL Server 2005

kobra94 Profilo | Newbie

PRemetto di non essere un esperto di Visual Basic anzi ho appena iniziata perchè sto facendo lo stage in una ditta...Comunque ho creato un database di Cd con titolo artista durata e Copertina su sql server tramite Vb sono riuscito a metterlo in un Datagridview per visualizzare tutte le copertine e ho creato dei comandi per aggiungere,eliminare o modificare record...ora mi è stato chiesto di fare un report dove vengano visualizzate anche le immagini qui mi sono bloccato ho provato e riprovato con Reportviewer ma proprio non riesco qualcuno sa dirmi passo per passo come fare? Grazie in anticipo...
Dato che non vedo molte risposte voglio inserire l'intero codice del mio programma giusto per dare un'idea...vorrei sapere se arrivato a questo punto possofare un report con tutti i campi del mio database...
Imports System.Data.SqlClient
Public Class Form1
Dim Mycn As New SqlConnection
Dim MyCmd As New SqlCommand
Dim myAdapter As New SqlDataAdapter
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: questa riga di codice carica i dati nella tabella 'CDDataSet.CD'. È possibile spostarla o rimuoverla se necessario.
Me.CDTableAdapter.Fill(Me.CDDataSet.CD)
Mycn.ConnectionString = "Data Source=svr01;Database=CD;User ID=sa;Password=123"
Dim s As String
Dim a As Integer = (DataGridView1.RowCount - 2)
Try
Mycn.Open()
Catch ex As Exception
MsgBox("Non sono riuscito a connettermi")
End Try
MyCmd.Connection = Mycn
For i As Integer = 0 To a
DataGridView1.Rows(i).Height = 60
s = ("C:\Documents and Settings\simone\Documenti\Immagini\Giovanni CD\" & DataGridView1.Rows(i).Cells(4).Value)
Dim bm As New Bitmap(s)
Me.DataGridView1.Rows(i).Cells(5).Value = bm
MyCmd.CommandText = ("UPDATE CD SET Immagine = '" & s & "' WHERE Nome = '" & DataGridView1.Rows(i).Cells(0).Value & "'")
MyCmd.ExecuteNonQuery()
Next
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim MyCmd As New SqlCommand
Dim nom, art, cop As String
Dim dur, bra As Integer
nom = InputBox("Inserisci nome", "Input box")
art = InputBox("Inserisci artista", "Input box")
bra = InputBox("Inserisci n° brani", "Input box")
dur = InputBox("Inserisci durata cd", "Input box")
cop = InputBox("inserisci nome copertina", "input box") & ".jpg"
MyCmd.Connection = Mycn
MyCmd.CommandText = "INSERT INTO CD(Nome,Artista,Brani,Durata,Copertina) VALUES('" & nom & "','" & art & "','" & bra & "','" & dur & "','" & cop & "')"
MyCmd.ExecuteNonQuery()
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim MyCmd As New SqlCommand
MyCmd.Connection = Mycn
Dim o As String
o = InputBox("Inserisci Cd da eliminare", "Input Box")
MyCmd.CommandText = ("DELETE FROM CD WHERE Nome= '" & o & "'")
MyCmd.ExecuteNonQuery()
End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Dim MyCmd As New SqlCommand
MyCmd.Connection = Mycn
Dim o As String
Dim nom, art, cop As String
Dim dur, bra, i As Integer
o = InputBox("Inserisci Cd da modificare", "Input Box")
i = InputBox("Per modificare interamente il record digitare 0 per modificare solo un campo del record digitare 1", "input box")
If i = 0 Then
nom = InputBox("Inserisci nome", "Input box")
art = InputBox("Inserisci artista", "Input box")
bra = InputBox("Inserisci n° brani", "Input box")
dur = InputBox("Inserisci durata cd", "Input box")
cop = InputBox("inserisci nome copertina", "input box") & ".jpg"
MyCmd.CommandText = ("UPDATE CD SET Nome = '" & nom & "',Artista = '" & art & "',Durata = '" & dur & "',Brani= '" & bra & "',Copertina= '" & cop & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
Else
Dim s As String
s = InputBox("Inserisci campo da modificare", "Input Box")
Select Case s
Case "Nome"
nom = InputBox("Inserisci nome", "Input box")
MyCmd.CommandText = ("UPDATE CD SET Nome = '" & nom & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
Case "Artista"
art = InputBox("Inserisci artista", "Input box")
MyCmd.CommandText = ("UPDATE CD SET Artista = '" & art & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
Case "Brani"
bra = InputBox("Inserisci n° brani", "Input box")
MyCmd.CommandText = ("UPDATE CD SET Brani = '" & bra & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
Case "Durata"
dur = InputBox("Inserisci durata cd", "Input box")
MyCmd.CommandText = ("UPDATE CD SET Durata = '" & dur & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
Case "Copertina"
cop = InputBox("inserisci nome copertina", "input box") & ".jpg"
MyCmd.CommandText = ("UPDATE CD SET Copertina = '" & cop & "' WHERE Nome = '" & o & "'")
MyCmd.ExecuteNonQuery()
End Select
End If
End Sub

Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
'TODO: questa riga di codice carica i dati nella tabella 'CDDataSet.CD'. È possibile spostarla o rimuoverla se necessario.
Me.CDTableAdapter.Fill(Me.CDDataSet.CD)
Dim s As String
Dim a As Integer = (DataGridView1.RowCount - 2)
MyCmd.Connection = Mycn
For i As Integer = 0 To a
DataGridView1.Rows(i).Height = 60
s = ("C:\Documents and Settings\simone\Documenti\Immagini\Giovanni CD\" & DataGridView1.Rows(i).Cells(4).Value)
Dim bm As New Bitmap(s)
Me.DataGridView1.Rows(i).Cells(5).Value = bm
MyCmd.CommandText = ("UPDATE CD SET Immagine = '" & s & "' WHERE Nome = '" & DataGridView1.Rows(i).Cells(0).Value & "'")
MyCmd.ExecuteNonQuery()
Next
End Sub

Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
Dim SecondoForm As New Form2
SecondoForm.Show()
End Sub
End Class
Ok naturalmente Click 5 richiamo un secondo Form nel quale andranno poi le istruzioni per creare il Report...

freeteo Profilo | Guru

Ciao,
prova a guardare questo post: http://www.dotnethell.it/forum/messages.aspx?ThreadID=37051
dovrebbe fare proprio al caso tuo....

Ciao.

Matteo Raumer
[MCAD .net, MVP Visual C#]
http://blogs.dotnethell.it/freeteo
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5