Im having a little bit of trouble with an update statement.
if any one could take a look at it and help me with what im doing wrong that would be great.
private void button6_Click(object sender, EventArgs e)
// Button6 is OK
{
///////If Null/////
if ((textBox1.Text.Length == 0) || (textBox2.Text.Length == 0))
{
MessageBox.Show("Fields cannot be empty");
return;
}
//
// Make sure there are no duplicates
DataSet ds = new DataSet();
DBconnect db = new DBconnect();
string Emp = new Department('K', textBox2.Text).SetSql();
ds = db.GetDataSet(Emp);
DataTable dt = ds.Tables[0];
//
if (dt.Rows.Count > 0)
{
MessageBox.Show("Duplicate Record");
}
else
{
// Connect to Database
OleDbConnection connect = new OleDbConnection();
connect = new DBconnect().DbConn("");
string UpdateStatement = "UPDATE Department "
+ "SET [Department] = ?, [Description] = ? "
+ "WHERE Department = '" + textBox2.Text + "'";
OleDbCommand UpdateCommand = new OleDbCommand(UpdateStatement, connect);
UpdateCommand.Parameters.Add("[Department]", OleDbType.Char).Value = textBox2.Text;
UpdateCommand.Parameters.Add("[Description]", OleDbType.Char).Value = textBox1.Text;
connect.Open();
int count = UpdateCommand.ExecuteNonQuery();
connect.Close();
this.Close();
}
}
it has no errors it just doesnt update the database or the datagrid.