Что мне нужно, это предотвратить обновление некоторых столбцов.Мне нужны эти поля, но я должен быть уверен, что они не будут обновлены даже по ошибке.Так есть ли свойство, которое нужно установить, чтобы эти поля были только в состоянии только для чтения?Для большей ясности, мой результат запроса представлен четырьмя полями:
trackingNumber, trackingStatus, shippingCode, shippingDate
Первые два будут обновлены, но последние два не будут измененыи я хочу быть уверен, что даже при ошибке их нельзя было изменить.
Есть ли способ?
public static Dictionary<string, object> GetTrackingShippingInfo(string carrierCode, DateTime date) {
SqlCommand cmd = new SqlCommand(String.Format(@"
( SELECT salesShipment.[Shipping Agent Ref_] as trackingNumber,
salesShipment.[Tracking Status] as trackingStatus,
salesShipment.[No_] as shippingCode,
salesShipment.[Posting Date] as shippingDate
FROM {0}.[{1}$Sales Shipment Header] as salesShipment
WHERE salesShipment.[Shipping Agent Code] = @carrierCode AND
salesShipment.[Posting Date] = @date AND
salesShipment.[Export to Carrier] > 0 AND
salesShipment.[Location Code] = @departureWarehouse
)
UNION ALL
( SELECT transferShipment.[Shipping Agent Ref_] as trackingNumber,
transferShipment.[Tracking Status] as trackingStatus,
transferShipment.[No_] as shippingCode,
transferShipment.[Posting Date] as shippingDate
FROM {0}.[{1}$Transfer Shipment Header] as transferShipment
WHERE transferShipment.[Shipping Agent Code] = @carrierCode AND
transferShipment.[Tipo Soggetto 1] = 1 AND
transferShipment.[Posting Date] = @date AND
transferShipment.[Export to Carrier] > 0 AND
transferShipment.[Transfer-from Code] = @departureWarehouse
)", navDbPrefix, navCompany));
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@carrierCode", carrierCode);
cmd.Parameters.AddWithValue("@date", String.Format("{0:yyyy-MM-dd}", date));
cmd.Parameters.AddWithValue("@departureWarehouse", "MP");
Dictionary<string, object> selectResult = DbHelper.ExecuteSelectForUpdateQuery(cmd);
return selectResult;
}
public static void UpdateTrackingShippingInfo(DataTable dataTable, SqlDataAdapter adapter) {
try
{
DbHelper.BeginTransaction();
DbHelper.ExecuteUpdate(dataTable, adapter);
DbHelper.CommmitTransaction();
}
catch (Exception e)
{
DbHelper.RollbackTransaction();
log.Error("Failed update query. Rollback executed");
log.Error(e.ToString());
}
}
public static void ExecuteUpdate(DataTable data, SqlDataAdapter adapter)
{
SqlCommandBuilder cmdBuilder;
cmdBuilder = new SqlCommandBuilder(adapter);
log.Debug(cmdBuilder.GetUpdateCommand().CommandText);
adapter.Update(data);
}