Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
String uname = tbUser.Text;
            String pass = tbPasswd.Text;
            string ConnString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\diy.mdb";
            string SqlString = "UPDATE Login SET user='" + uname + "',paswrd='" + pass + "'";
           OleDbConnection conn = new OleDbConnection(ConnString);
           OleDbCommand cmd = new OleDbCommand(SqlString, conn);
           conn.Open();
           cmd.ExecuteNonQuery();
           conn.Close();
Posted
Updated 9-Aug-15 21:30pm
v2

1 solution

use sql parameters and also you need to use [] for reserved keywords like user [^]
C#
using (var connection = new OleDbConnection(ConnString ))
using (var command = connection.CreateCommand())
{
    connection.Open();
    command.CommandText = "UPDATE Login SET [user]=?,paswrd=?";
    command.Parameters.AddWithValue("@user", uname );
    command.Parameters.AddWithValue("@pwd", pass );
command.ExecuteNonQuery();

}
 
Share this answer
 
v2
Comments
CPallini 10-Aug-15 3:09am    
5
Member 11821221 10-Aug-15 3:20am    
Thank you .......
Maciej Los 10-Aug-15 3:36am    
Jet for MS Access does not know named parameters with @ prefix. Instead of above use named parameters for MS Access database or standard OleDb parameters (no-named) - via using: ?.
DamithSL 10-Aug-15 3:52am    
Thanks Maciej, I have updated my answer.
Maciej Los 10-Aug-15 4:10am    
The second part of your answer (code) is wrong still.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900