ti dò una traccia: è in Basic e lo lascio in Basic e non lo traduco in c#

pagina aspx
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="comandi parametrici con transazione.aspx.vb" Inherits="CorsoApogeo_wrox_gestione_dati_comandi_parametrici_con_transazione" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Pagina senza titolo</title>
    <link href="../../../stili/Styles.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
// <!CDATA[

function window_onload() 
{
	var messaggioJS = "<%=messaggioJS%>";
	if(messaggioJS.length != 0) alert(messaggioJS);

}

// ]]>
</script>
</head>
<body onload="return window_onload()">
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>
</body>
</html>

CodeFile
codice:
Option Strict On

Partial Class CorsoApogeo_wrox_gestione_dati_comandi_parametrici_con_transazione
    Inherits System.Web.UI.Page

    Protected messaggioJS$ = "" 'serve nel client

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Connessione As OleDbConnection = Nothing
        Dim Comando As OleDbCommand = Nothing
        Dim Transazione As OleDbTransaction = Nothing
        Dim Sql$ = ""

        Try
            Connessione = New OleDbConnection(StringaConnessioneTest)
            Connessione.Open()
            Transazione = Connessione.BeginTransaction()
            Comando = New OleDbCommand
            Comando.Connection = Connessione
            Comando.Transaction = Transazione

            Append(Comando)
            Update(Comando)
            Delete(Comando)

            'Transazione.Commit()
            Transazione.Rollback()

            messaggioJS = toStringaJS("Operazioni su database eseguite regolarmente")



        Catch ex As Exception
            If (Not (Transazione Is Nothing) AndAlso Not (Transazione.Connection Is Nothing)) Then Transazione.Rollback()
            Me.messaggioJS = toStringaJS("Errore nell'aggiornamento:" & vbNewLine & vbNewLine & exMessage(ex))

        Finally
            If (Not (Connessione Is Nothing)) Then Connessione.Close()
        End Try
    End Sub

    Private m_prossimo_id% = 0

    Private Sub Append(ByVal Comando As OleDbCommand)
        Me.m_prossimo_id = libreria.ProssimoIDAccess(Comando, "campi", "id")
        Dim Sql$ = "INSERT INTO [CAMPI] ( [PASSWORD], [TESTO], [MEMO], [DATA_ORA], [VALUTA], [SI_NO], [BYTE], [INTERO], [LONG], [SINGLE], [DOUBLE], [DECIMALE], [ID]) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?) "
        Comando.CommandText = Sql

        Comando.Parameters.Clear()

        Comando.Parameters.Add("password", OleDbType.VarChar, 50).Value = DBNull.Value
        Comando.Parameters.Add("testo", OleDbType.VarChar, 50).Value = DBNull.Value
        Comando.Parameters.Add("memo", OleDbType.VarChar, 60000).Value = DBNull.Value
        Comando.Parameters.Add("data_ora", OleDbType.Date).Value = DBNull.Value
        Comando.Parameters.Add("valuta", OleDbType.Currency).Value = DBNull.Value
        Comando.Parameters.Add("si_no", OleDbType.Boolean).Value = DBNull.Value
        Comando.Parameters.Add("byte", OleDbType.TinyInt).Value = DBNull.Value
        Comando.Parameters.Add("intero", OleDbType.Integer).Value = DBNull.Value
        Comando.Parameters.Add("long", OleDbType.Integer).Value = DBNull.Value
        Comando.Parameters.Add("single", OleDbType.Single).Value = DBNull.Value
        Comando.Parameters.Add("double", OleDbType.Double).Value = DBNull.Value
        Comando.Parameters.Add("decimal", OleDbType.Decimal).Value = DBNull.Value

        Comando.Parameters.Add("id", OleDbType.Integer).Value = Me.m_prossimo_id

        Comando.ExecuteNonQuery()


    End Sub

    Private Sub Update(ByVal Comando As OleDbCommand)
        Dim Sql$ = "UPDATE [CAMPI] SET [PASSWORD] = ?, [TESTO] = ?, [MEMO] = ?, [DATA_ORA] = ?, [VALUTA] = ?, [SI_NO] = ?, [BYTE] = ?, [INTERO] = ?, [LONG] = ?, [SINGLE] = ?, [DOUBLE] = ?, [DECIMALE] = ? WHERE [ID] = ? "
        Comando.CommandText = Sql

        Comando.Parameters.Clear()

        Comando.Parameters.Add("password", OleDbType.VarChar, 50).Value = DBNull.Value
        Comando.Parameters.Add("testo", OleDbType.VarChar, 50).Value = DBNull.Value
        Comando.Parameters.Add("memo", OleDbType.VarChar, 60000).Value = DBNull.Value
        Comando.Parameters.Add("data_ora", OleDbType.Date).Value = DBNull.Value
        Comando.Parameters.Add("valuta", OleDbType.Currency).Value = DBNull.Value
        Comando.Parameters.Add("si_no", OleDbType.Boolean).Value = DBNull.Value
        Comando.Parameters.Add("byte", OleDbType.TinyInt).Value = DBNull.Value
        Comando.Parameters.Add("intero", OleDbType.Integer).Value = DBNull.Value
        Comando.Parameters.Add("long", OleDbType.Integer).Value = DBNull.Value
        Comando.Parameters.Add("single", OleDbType.Single).Value = DBNull.Value
        Comando.Parameters.Add("double", OleDbType.Double).Value = DBNull.Value
        Comando.Parameters.Add("decimal", OleDbType.Decimal).Value = DBNull.Value

        Comando.Parameters.Add("id", OleDbType.Integer).Value = Me.m_prossimo_id

        Comando.ExecuteNonQuery()

    End Sub

    Private Sub Delete(ByVal Comando As OleDbCommand)
        Dim Sql$ = "DELETE FROM [CAMPI] WHERE [ID] = ? "
        Comando.CommandText = Sql

        Comando.Parameters.Clear()

        Comando.Parameters.Add("id", OleDbType.Integer).Value = Me.m_prossimo_id

        Comando.ExecuteNonQuery()

    End Sub

End Class
qulche nota:
L'esempio fa tre operazioni su database Access: Append, Update e Delete.
Lo fa utilizzando una transazione: se tutto va a buon fine, fa il Commit, altrimenti fa il Rollback

Nell'esempio faccio sempre il Rollback perchè sono interessato al collaudo e non a scrivere veramente i dati: tu devi commentare il Rollback e disicomentare il Commit.

Il codice inserisce SOLO valori nulli, DBNull.Value. Tu devi metterci invece i valori ricevuti dal form, per esempio un campo testo: CampoTesto.Text

La comunicazione col database è fatta esclusivamente con i parametri. L'uso dei parametri se vuoi fare una cosa ben fatta, lo devi considerare come obbligatorio.

Con Access, non conta niente il nome dei parametri, ma solo il loro ordine. Per esempio:

UPDATE [CAMPI] SET [PASSWORD] = ?, [TESTO] = ?, [MEMO] = ?,***
bisogna immettere i parametri password, testo e memo, ***, nell'ordine

nel mio esempio la tabella si chiama CAMPI ed i campi hanno nomi riservati, come password, ect, perciò li si deve chiudere con parentesi quadre.