codice:
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...