I have following code to set the text box values on page load.
protected void Page_Load(object sender, EventArgs e)
{
localhost.UserRegistration m = new localhost.UserRegistration();
int user = m.ID(Session["Username"].ToString());
DataSet ds = m.GetUserInfo(user);
if (ds.Tables.Count > 0)
{
TextBox1.Text = ds.Tables[0].Rows[0]["emailAddress"].ToString();
TextBox2.Text = ds.Tables[0].Rows[0]["password"].ToString();
}
}
So when first user opens the page, the user will be shown their email address and password in textbox. when they make changes and click update, the same value that was on page load will be sent to the database, not the new one that is changed.
I have the following web service method to update the user details
[WebMethod(Description = "Updates a single user")]
public string UpdateUser(int user, string emailAddress, string password)
{
// Create connection object
int ix = 0;
string rTurn = "";
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "UPDATE [User] SET [emailAddress]=@emailAddress, [password]=@password" + " WHERE [ID]=@user";
OleDbCommand oleComm = new OleDbCommand(sql, oleConn);
oleComm.Parameters.Add("@user", OleDbType.Integer).Value = user;
oleComm.Parameters.Add("@emailAddress", OleDbType.Char).Value = emailAddress;
oleComm.Parameters.Add("@password", OleDbType.Char).Value = password;
ix = oleComm.ExecuteNonQuery();
if (ix > 0)
rTurn = "User Updated";
else
rTurn = "Update Failed";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
rTurn = ex.ToString();
}
finally
{
oleConn.Close();
}
return rTurn;
}
This is how table look in database

Client Side Code
protected void Button1_Click(object sender, EventArgs e)
{
string email = TextBox1.Text;
string pass = TextBox2.Text;
localhost.UserRegistration m = new localhost.UserRegistration();
int usr = m.ID(Session["Username"].ToString());
m.UpdateUser(usr, email, pass);
}
Can Somebody tell me why….
I think you are mixing up SqlParameters and OleDbParameters. OleDbParameters does not support named parameters!!
see MSDN OleDbCommand.Parameters
I think you should adapt your code to
EDIT