Hello!
I'm not sure what's going wrong here:
So, essentially I've got a MSACCESS backend attached to this thing. I'm looking to see if the airportIDENT exists in the database already. If it does, we're updating, if it doesn't we're inserting it. The INSERT works just fine when recs = 0. However, when recs = 1, the UPDATE query fails to update the existing row. I'm not sure if it's an issue with the UPDATE query itself, or the conditional statement. I suspect it's the update query itself, as the else if fires when recs = 0.
Any ideas? As always, assistance is always appreciated!
*EDIT* Also, there are absolutely no errors thrown, syntax or otherwise. In fact, I've purposefully screwed with the syntax of the update statement just so I could get an error thrown to make sure my conditional statement was even "trying" to fire.
I'm not sure what's going wrong here:
C#:
connection.Open(); OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "SELECT COUNT(*) FROM tblAirportData WHERE airportIDENT LIKE @airportIdent";
command.Parameters.AddWithValue("@airportIdent", txtAirportIdentifier.Text);
int recs = (int)command.ExecuteScalar();
MessageBox.Show(recs.ToString()); //just peeking to see if anything was found.
if (recs > 0)
{
command.CommandText = "UPDATE tblAirportData SET airportNAME=@airportName, airportIDENT=@airportIdent, airportCITY=@city, airportSTATE=@state WHERE ID = @ID";
command.Parameters.AddWithValue("@airportName", txtAirportName.Text);
command.Parameters.AddWithValue("@airportIdent", txtAirportIdentifier.Text);
command.Parameters.AddWithValue("@city", txtCity.Text);
command.Parameters.AddWithValue("@state", cboState.Text);
command.Parameters.AddWithValue("@ID", lblAirportID.Text); //I've tried parsing this as Int32 with no effect.
command.ExecuteNonQuery();
connection.Close();
}
else if (recs < 0)
{
command.CommandText = "INSERT INTO tblAirportData (airportNAME, airportIDENT, airportCity, airportState) VALUES (@airportName, @airportIdent, @city, @state)";
command.Parameters.AddWithValue("@airportName", txtAirportName.Text);
command.Parameters.AddWithValue("@airportIdent", txtAirportIdentifier.Text);
command.Parameters.AddWithValue("@city", txtCity.Text);
command.Parameters.AddWithValue("@state", cboState.Text);
command.ExecuteNonQuery();
connection.Close();
}
else
{
MessageBox.Show("Something unexpected happened");
connection.Close();
}
So, essentially I've got a MSACCESS backend attached to this thing. I'm looking to see if the airportIDENT exists in the database already. If it does, we're updating, if it doesn't we're inserting it. The INSERT works just fine when recs = 0. However, when recs = 1, the UPDATE query fails to update the existing row. I'm not sure if it's an issue with the UPDATE query itself, or the conditional statement. I suspect it's the update query itself, as the else if fires when recs = 0.
Any ideas? As always, assistance is always appreciated!
*EDIT* Also, there are absolutely no errors thrown, syntax or otherwise. In fact, I've purposefully screwed with the syntax of the update statement just so I could get an error thrown to make sure my conditional statement was even "trying" to fire.
Last edited: