I am trying to update an ID value. So if the ID is 1 the new value is 2 it should replace the old ID with the new.
Back end:
public static void UpdateLocation( int locationID, SqlConnection connection, SqlTransaction transaction )
{
StringBuilder sqlString = new StringBuilder();
SqlCommand command;
sqlString.Append( "UPDATE [Location] SET " );
sqlString.Append( "description = @description " );
sqlString.Append( "WHERE locationID = @locationID " );
command = new SqlCommand( sqlString.ToString(), connection );
if( ( transaction != null ) ) command.Transaction = transaction;
command.Parameters.Add( "@locationID", SqlDbType.Int ).Value = locationID;
command.Parameters.Add( "@description", SqlDbType.VarChar ).Value = description;
int rowsAffected = command.ExecuteNonQuery();
if( !( rowsAffected == 1 ) )
{
throw new Exception( "An error has occurred while updating UpdateMedicationDispenseStatus." );
}
}
Front End:
private void btnFromLocation_Click( object sender, System.Windows.RoutedEventArgs e )
{
if( !( ( Locations )cmbLocationDescriptionList.SelectedItem == ( Locations )cmbDescriptionListTo.SelectedItem ) )
{
for( int i = 0; i < lstMedicationForCurrentLocation.SelectedItems.Count; i++ )
{
location = (Locations)cmbDescriptionListTo.SelectedItem;
LocationData.UpdateLocation( location.LocationID );
EDIT I have added a parameter to the SQL Query but still doesnt Update