ID 値を更新しようとしています。したがって、ID が 1 の場合、新しい値は 2 で、古い ID を新しい ID に置き換える必要があります。
バックエンド:
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." );
}
}
フロントエンド:
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 SQLクエリにパラメータを追加しましたが、まだ更新されていません