Ciao a tutti, sono veramente disperato.
L'applicazione che ho creato non mi funziona, ma non riesco a capire dove ho fatto l'errore. Forse ho letto il codice talmente tante volte che mi sono convinto sia corretto. Mi aiutereste a farlo funzionare?
Di seguito posto il codice:
Grazie in anticipo a chi ci perde un po' di tempo......codice:Public Class Form3 Dim cnn As New OleDb.OleDbConnection Dim cmd As New OleDb.OleDbCommand Dim dt As New DataTable Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click sito.Text = "" utente.Text = "" mail.Text = "" password.Text = "" appunti.Text = "" Button3.Enabled = True Button4.Text = "Aggiungi" sito.Select() End Sub Private Sub RefreshData() If Not cnn.State = ConnectionState.Open Then 'apri connessione se è ancora chiusa cnn.Open() End If Dim das As New OleDb.OleDbDataAdapter("SELECT sito as [Sito], " & _ "utente as [Utente], mail , password, appunti " & _ "FROM dati ORDER BY sito", cnn) Dim dt As New DataTable das.Fill(dt) Me.dati.DataSource = dt 'chiudi connessione cnn.Close() End Sub Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click Dim cmd As New OleDb.OleDbCommand If Not cnn.State = ConnectionState.Open Then 'apri connessione se è ancora chiusa cnn.Open() End If cmd.Connection = cnn 'aggiungi dati alla tabella cmd.CommandText = "INSERT INTO dati(sito, utente, mail, password, appunti) " & _ "VALUES(" & sito.Text & ",'" & utente.Text & "','" & _ mail.Text & "','" & password.Text & "','" & appunti.Text & "')" cmd.ExecuteNonQuery() 'aggiorna dati nella lista RefreshData() Button1.PerformClick() 'chiudi connessione cnn.Close() End Sub Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load cnn = New OleDb.OleDbConnection cnn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\data.mdb" RefreshData() End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click If dati.Rows.Count > 0 Then If dati.SelectedRows.Count > 0 Then Dim intDati As Integer = dati.SelectedRows(0).Cells("sito").Value If Not cnn.State = ConnectionState.Open Then 'apri connessione se è ancora chiusa cnn.Open() End If Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM dati " & _ " WHERE sito=" & intDati, cnn) Dim dt As New DataTable da.Fill(dt) sito.Text = intDati utente.Text = dt.Rows(0).Item("utente") mail.Text = dt.Rows(0).Item("mail") password.Text = dt.Rows(0).Item("password") appunti.Text = dt.Rows(0).Item("appunti") Button4.Text = "Aggiorna" Button3.Enabled = False cnn.Close() End If End If End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click If dati.Rows.Count > 0 Then If dati.SelectedRows.Count > 0 Then Dim intDati As Integer = dati.SelectedRows(0).Cells("sito").Value If Not cnn.State = ConnectionState.Open Then 'apri connessione se è ancora chiusa cnn.Open() End If Dim cmd As New OleDb.OleDbCommand cmd.Connection = cnn cmd.CommandText = "DELETE FROM dati WHERE sito=" & intDati cmd.ExecuteNonQuery() RefreshData() cnn.Close() End If End If End Sub End Class
Joe

Rispondi quotando