C# database avec oledb user et password
danmor
Messages postés
31
Statut
Membre
-
holow1 Messages postés 739 Statut Membre -
holow1 Messages postés 739 Statut Membre -
Bonjour,
Voila mon probleme est que je recoit l'erreur
Erreur de syntaxe dans UPdate
kkun peut m'aider la dessus
void SaveData()
{
// Ce qui est en fait unUpdate
string strProv = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Data\\Users.mdb;" + "Jet OLEDB:Engine Type=5";
OleDbConnection connection ;
OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
connection = new OleDbConnection(strProv);
string sql = "UPDATE Users SET UserName=UserNameText.Text, Password=NewUserPasswordText.Text WHERE UserID=1";
try
{
connection.Open();
oledbAdapter.UpdateCommand = connection.CreateCommand();
oledbAdapter.UpdateCommand.CommandText = sql;
oledbAdapter.UpdateCommand.ExecuteNonQuery();
MessageBox.Show ("Row(s) Updated !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
--
MERCI
BigDan
Voila mon probleme est que je recoit l'erreur
Erreur de syntaxe dans UPdate
kkun peut m'aider la dessus
void SaveData()
{
// Ce qui est en fait unUpdate
string strProv = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Data\\Users.mdb;" + "Jet OLEDB:Engine Type=5";
OleDbConnection connection ;
OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
connection = new OleDbConnection(strProv);
string sql = "UPDATE Users SET UserName=UserNameText.Text, Password=NewUserPasswordText.Text WHERE UserID=1";
try
{
connection.Open();
oledbAdapter.UpdateCommand = connection.CreateCommand();
oledbAdapter.UpdateCommand.CommandText = sql;
oledbAdapter.UpdateCommand.ExecuteNonQuery();
MessageBox.Show ("Row(s) Updated !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
--
MERCI
BigDan
Configuration: Windows XP / Internet Explorer 7.0
2 réponses
-
void SaveData()
{
// Ce qui est en fait unUpdate
string strProv = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=Data\\Users.mdb;" + "Jet OLEDB:Engine Type=5";
OleDbConnection connection ;
OleDbDataAdapter oledbAdapter = new OleDbDataAdapter();
connection = new OleDbConnection(strProv);
string sql = "UPDATE Users SET UserName= " + UserNameText.Text +", Password= " + NewUserPasswordText.Text +" WHERE UserID=1";
try
{
connection.Open();
oledbAdapter.UpdateCommand = connection.CreateCommand();
oledbAdapter.UpdateCommand.CommandText = sql;
oledbAdapter.UpdateCommand.ExecuteNonQuery();
MessageBox.Show ("Row(s) Updated !! ");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
} -
UserNameText.Text et NewUserPasswordText.Text ce sont des controles(zone de text) dans votre form ?
donc il faut faut faire une concaténation pas l'affecter directement a votre champs UserName et Password