2016-04-28 26 views
-1

ich diesen Code verwenden die Datenbank zu aktualisieren:Meine Access DB wird nicht aktualisiert. Keine Fehler im Code

var connectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString; 
string commandString = string.Empty; 
using (OleDbConnection con = new OleDbConnection(connectionString)) 
{ 
    con.Open(); 
    OleDbCommand command = new OleDbCommand(commandString, con); 
    commandString = "UPDATE accesscontrol SET [email protected] WHERE [email protected] AND [email protected]"; 

    command.Parameters.AddWithValue("userName", Environment.UserName); 
    command.Parameters.AddWithValue("isEnabled", tempPerson.isBool.ToString()); 
    command.Parameters.AddWithValue("userNameInGrid", tempPerson.Name); 
    command.ExecuteNonQuery(); 
    command.Parameters.Clear(); 
} 

Antwort

1

Weil Sie verwenden leer commandString

Zuerst gesetzt:

string commandString = string.Empty; 

Und dann übergeben Sie leer commandString zu OleDbCommand, danach setzen Sie den Wert auf Variable commandString aber nicht auf OleDbCommand

OleDbCommand command = new OleDbCommand(commandString, con); 
commandString = "UPDATE accesscontrol SET [email protected] WHERE [email protected] AND [email protected]"; 

Ändern Sie Code:

commandString = "UPDATE accesscontrol SET [email protected] WHERE [email protected] AND [email protected]"; 
OleDbCommand command = new OleDbCommand(commandString, con); 

UPDATE

Auch sollten Sie @ vor Parameternamen hinzufügen

command.Parameters.AddWithValue("@userName", Environment.UserName); 
command.Parameters.AddWithValue("@isEnabled", tempPerson.isBool.ToString()); 
command.Parameters.AddWithValue("@userNameInGrid", tempPerson.Name); 
+0

ich die Änderung vorgenommen hat und Tabelle wird nicht –

+0

aktualisiert @ softwareisfun Bitte sehen Sie mein Update – Marusyk

+0

@softwareisfun Irgendwelche Neuigkeiten? War es hilfreich? – Marusyk