本文整理汇总了C#中System.Data.SqlClient.SqlParameter.GetCoercedValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlParameter.GetCoercedValue方法的具体用法?C# SqlParameter.GetCoercedValue怎么用?C# SqlParameter.GetCoercedValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlParameter
的用法示例。
在下文中一共展示了SqlParameter.GetCoercedValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSmiParameter
private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefault, TdsParserStateObject stateObj)
{
//
// Determine Metadata
//
ParameterPeekAheadValue peekAhead;
MSS.SmiParameterMetaData metaData = param.MetaDataForSmi(out peekAhead);
if (!_isKatmai)
{
MetaType mt = MetaType.GetMetaTypeFromSqlDbType(metaData.SqlDbType, metaData.IsMultiValued);
throw ADP.VersionDoesNotSupportDataType(mt.TypeName);
}
//
// Determine value to send
//
object value;
MSS.ExtendedClrTypeCode typeCode;
// if we have an output or default param, set the value to null so we do not send it across to the server
if (sendDefault)
{
// Value for TVP default is empty list, not NULL
if (SqlDbType.Structured == metaData.SqlDbType && metaData.IsMultiValued)
{
value = s_tvpEmptyValue;
typeCode = MSS.ExtendedClrTypeCode.IEnumerableOfSqlDataRecord;
}
else
{
// Need to send null value for default
value = null;
typeCode = MSS.ExtendedClrTypeCode.DBNull;
}
}
else if (param.Direction == ParameterDirection.Output)
{
bool isCLRType = param.ParamaterIsSqlType; // We have to forward the TYPE info, we need to know what type we are returning. Once we null the paramater we will no longer be able to distinguish what type were seeing.
param.Value = null;
value = null;
typeCode = MSS.ExtendedClrTypeCode.DBNull;
param.ParamaterIsSqlType = isCLRType;
}
else
{
value = param.GetCoercedValue();
typeCode = MSS.MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(metaData.SqlDbType, metaData.IsMultiValued, value);
}
//
// Write parameter metadata
//
WriteSmiParameterMetaData(metaData, sendDefault, stateObj);
//
// Now write the value
//
TdsParameterSetter paramSetter = new TdsParameterSetter(stateObj, metaData);
MSS.ValueUtilsSmi.SetCompatibleValueV200(
new MSS.SmiEventSink_Default(), // TDS Errors/events dealt with at lower level for now, just need an object for processing
paramSetter,
0, // ordinal. TdsParameterSetter only handles one parameter at a time
metaData,
value,
typeCode,
param.Offset,
0 < param.Size ? param.Size : -1,
peekAhead);
}
示例2: WriteSmiParameter
private void WriteSmiParameter(SqlParameter param, int paramIndex, bool sendDefault, TdsParserStateObject stateObj)
{
object coercedValue;
ExtendedClrTypeCode iEnumerableOfSqlDataRecord;
ParameterPeekAheadValue value2;
SmiParameterMetaData metaData = param.MetaDataForSmi(out value2);
if (!this._isKatmai)
{
throw ADP.VersionDoesNotSupportDataType(MetaType.GetMetaTypeFromSqlDbType(metaData.SqlDbType, metaData.IsMultiValued).TypeName);
}
if (sendDefault)
{
if ((SqlDbType.Structured == metaData.SqlDbType) && metaData.IsMultiValued)
{
coercedValue = __tvpEmptyValue;
iEnumerableOfSqlDataRecord = ExtendedClrTypeCode.IEnumerableOfSqlDataRecord;
}
else
{
coercedValue = null;
iEnumerableOfSqlDataRecord = ExtendedClrTypeCode.DBNull;
}
}
else if (param.Direction == ParameterDirection.Output)
{
bool paramaterIsSqlType = param.ParamaterIsSqlType;
param.Value = null;
coercedValue = null;
iEnumerableOfSqlDataRecord = ExtendedClrTypeCode.DBNull;
param.ParamaterIsSqlType = paramaterIsSqlType;
}
else
{
coercedValue = param.GetCoercedValue();
iEnumerableOfSqlDataRecord = MetaDataUtilsSmi.DetermineExtendedTypeCodeForUseWithSqlDbType(metaData.SqlDbType, metaData.IsMultiValued, coercedValue, null, 210L);
}
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.TdsParser.WriteSmiParameter|ADV> %d#, Sending parameter '%ls', default flag=%d, metadata:\n", this.ObjectID, param.ParameterName, sendDefault ? 1 : 0);
Bid.PutStr(metaData.TraceString(3));
Bid.Trace("\n");
}
this.WriteSmiParameterMetaData(metaData, sendDefault, stateObj);
TdsParameterSetter setters = new TdsParameterSetter(stateObj, metaData);
ValueUtilsSmi.SetCompatibleValueV200(new SmiEventSink_Default(), setters, 0, metaData, coercedValue, iEnumerableOfSqlDataRecord, param.Offset, (0 < param.Size) ? param.Size : -1, value2);
}