modify data in columns in SQL Server
I am trying to make a website written in C# in Visual Studio 2010. I got a database in .accdb extention.
So I go a table in the database called usertb
, and in the table username
is the key, and the data password
and DOB
in columns.
Now I need to make a function to edit a user profile, which lets the user to enter a new password and Date of Birth. After that, it will save to the database.
I don't know why the code seems to be not working. I tried to use
UPDATE ... SET ...WHERE ..
function but I don't know why it doesn't allow me to do that (is that because my code is written in C# but not PHP?)
Here is开发者_开发百科 the code for edit user profile: (srpassword
is the name of the password column, password
is the new one user typed in)
public static bool EditUserInfo(string username, string password)
{
string query = "SELECT REPLACE([srpassword], [srpassword], 'password')
FROM usertb WHERE srusername = '" + username + "'";
accessDB dbaccess = new accessDB();
return dbaccess.saveData(query);
}
Hope somebody can help me
The syntax select replace is from MySQL, in SQL Server the update statements goes like this
Also I'm no sure about that accessDB dbaccess = new accessDB();
, has the connection etc.
Also instead of combining statement you should use parameters, then your statement should look like this.
UPDATE usertb SET srpassowr = @password WHERE srusername = @userName;
As you have some class responsible for connection to db this example show how usually sql statemetns should be executed.
Did you try "UPDATE usertb SET [srpassword] = '" + password + "' WHERE [srusername] = '" + username + "'
?
I'm not going in details why Access is a bad choice, if you're using it only for prototyping it should be OK though.
精彩评论