Salve ragazzi buona giornata.
Dopo avere effettuato una ricerca mostro i dati in un DataGrid che ho nekl form1.
Ad ogni riga ho tre pulsanti che devono cancellare, inserire e eliminare il record.
Queste tre operazioni vengono effettuate in un nuovo form.
Per esempio per cancellare il prodotto, ho detto al pulsante di aprire il FORM 4 e di riepilogare in campi testo i dati da cancellare. Alla fine ho un pulsante che mi esegue la query sul FORM 4. I dati nei campi testo del FORM 4 li visualizzo dopo aver creato un DataGrid e li filtro tramite id.
Il problema è che quando eseguo la query per la cancellazione del record i dati non mi vengono cacellate dal db e io non ricevo nessun errore.
Ecco il codice che apre il FORM4:
codice:
If e.ColumnIndex = Me.DataGridResultRicerca.Columns("btnElimina").Index Then
Form4.Visible = True
Dim idDettaglio As Integer
idDettaglio = CType(DataGridResultRicerca.CurrentRow.Cells(3).Value, String)
Dim DataConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\magazzino.mdb;"
Dim cn As New OleDbConnection()
cn.ConnectionString = DataConnString
cn.Open()
Dim sql As String = "Select * from dettaglio WHERE id_dettaglio = " & idDettaglio & " Order By id_dettaglio"
Dim cmd As New OleDbCommand()
cmd.Connection = cn
cmd.CommandText = sql
Dim dad As OleDbDataAdapter = New OleDbDataAdapter(cmd)
Dim dataset As DataSet = New DataSet("dettaglio")
dad.Fill(dataset)
Form4.DataGridGestioneProdotto.DataSource = dataset
Form4.DataGridGestioneProdotto.DataMember = dataset.Tables(0).TableName
Form4.DataGridGestioneProdotto.Visible = False
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(0).Value Is System.DBNull.Value Then
Form4.txtIdDettaglio.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(0).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(1).Value Is System.DBNull.Value Then
Form4.txtSerialNumber.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(1).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(3).Value Is System.DBNull.Value Then
Form4.txtTipoArticolo.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(3).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(5).Value Is System.DBNull.Value Then
Form4.txtCodArticolo.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(5).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(9).Value Is System.DBNull.Value Then
Form4.txtFornitore.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(9).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(11).Value Is System.DBNull.Value Then
Form4.txtDataArrivo.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(11).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(4).Value Is System.DBNull.Value Then
Form4.txtMarca.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(4).Value
End If
If Not Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(6).Value Is System.DBNull.Value Then
Form4.txtDescrizionearticolo.Text = Form4.DataGridGestioneProdotto.Rows(Form4.DataGridGestioneProdotto.CurrentRow.Index).Cells(6).Value
End If
End If
questo è il codice di aggiornamento nel form4:
codice:
Private Sub btnCancellaArticolo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancellaArticolo.Click
Dim DataConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\magazzino.mdb;"
Dim cn As New OleDbConnection()
cn.ConnectionString = DataConnString
cn.Open()
Dim sql As String = "DELETE * FROM dettaglio WHERE id_dettaglio " & Me.txtIdDettaglio.Text & ""
Dim cmd As New OleDbCommand()
cmd.Connection = cn
cmd.CommandText = sql
cn.Close()
End Sub
Da cosa può dipendere?
Grazie a tutti.