问题是例如当我尝试更新姓氏时,它总是更新-1。 Ms-Access是数据库。
private void btnUpdate_Click(object sender, EventArgs e)
{
belobj.UserID = Convert.ToInt32(txtCustomerId.Text);
belobj.Firstname = txtFirstName.Text;
belobj.Lastname = txtLastName.Text;
belobj.Email = txtEmail.Text;
belobj.Username = txtUserName.Text;
belobj.Password = txtPassword.Text.Trim();
belobj.Enable = cmbEnable.Text.Trim();
if (gridcheck == true)
{
DialogResult dialogResult = MessageBox.Show("Do you want to save all pending changes ?", "Save Changes", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
string query = string.Format("UPDATE tbl_User SET Firstname= '" + belobj.Firstname + "' and Lastname= '" + belobj.Lastname + "' and Email= '" + belobj.Email + "' and Username= '" + belobj.Username + "' and Password= '" + belobj.Password + "' and Enable='" + belobj.Enable + "' where [UserID]= " + belobj.UserID + "");
if (balobj.UpdateQuery(query, belobj) > 0)
{
MessageBox.Show("Record Upadted Succesfully");
GenerateCustomerId();
}
else
{
}
gridcheck = false;
}
else if (dialogResult == DialogResult.No)
{
gridcheck = false;
BindGrid();
ControlClear();
GenerateCustomerId();
}
}
else
{
MessageBox.Show("Please select Any Customer !!");
return;
}
}
public int ExecuteUpdateQuery(String _query, BEL belobj)
{
try
{
oledbcomm.Connection = openConnection();
oledbcomm.CommandText = _query;
oledbcomm.Parameters.Add(new OleDbParameter("Firstname", belobj.Firstname));
oledbcomm.Parameters.Add(new OleDbParameter("Lastname", belobj.Lastname));
oledbcomm.Parameters.Add(new OleDbParameter("Email", belobj.Email));
oledbcomm.Parameters.Add(new OleDbParameter("Username", belobj.Username));
oledbcomm.Parameters.Add(new OleDbParameter("Password", belobj.Password));
oledbcomm.Parameters.Add(new OleDbParameter("Enable", belobj.Enable));
oledbcomm.Parameters.Add(new OleDbParameter("UserID", Convert.ToInt32(belobj.UserID)));
int x = oledbcomm.ExecuteNonQuery();
return x;
}
catch (Exception ex)
{
throw ex;
}
finally
{
oledbcomm.Dispose();
con.Close();
}
}