本文整理汇总了C#中Microsoft.SqlServer.Server.SqlDataRecord.SetDBNull方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDataRecord.SetDBNull方法的具体用法?C# SqlDataRecord.SetDBNull怎么用?C# SqlDataRecord.SetDBNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.SqlServer.Server.SqlDataRecord
的用法示例。
在下文中一共展示了SqlDataRecord.SetDBNull方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateMetaPropertyTable
protected static IEnumerable<SqlDataRecord> GenerateMetaPropertyTable(MetaObject o)
{
var metaFields = new List<SqlDataRecord>();
try
{
SqlMetaData[] metaData = new SqlMetaData[2];
metaData[0] = new SqlMetaData("FieldName", SqlDbType.VarChar, 30);
metaData[1] = new SqlMetaData("FieldValue", SqlDbType.VarChar, -1);
foreach (KeyValuePair<string, JToken> prop in o.MetaPropertiesObject)
{
SqlDataRecord record = new SqlDataRecord(metaData);
record.SetString(0, prop.Key);
// coming from the DB the value will be an object representing the field, with a "Value" key
// coming from the client the value will be a single value
var value = prop.Value.SelectToken("Value") ?? prop.Value;
if (value.Type == JTokenType.Null)
{
record.SetDBNull(1);
}
else
{
record.SetString(1, value.ToString());
}
metaFields.Add(record);
}
}
catch (Exception e)
{
}
return metaFields;
}
示例2: SetDateTimeRecord
public static void SetDateTimeRecord(SqlDataReader dr, string columnName, SqlDataRecord record, int ordinal)
{
if (dr[columnName] == DBNull.Value)
record.SetDBNull(ordinal);
else
record.SetDateTime(ordinal, Convert.ToDateTime(dr[columnName]));
}
示例3: SendRow
public void SendRow(SqlDataRecord dataRecord, object[] items)
{
for (int i = 0; i < items.Length; i++)
{
string value = items[i].ToStringSafe();
if (string.IsNullOrEmpty(value))
{
dataRecord.SetDBNull(i);
}
else
{
dataRecord.SetString(i, value);
}
}
if (SqlContext.IsAvailable && SqlContext.Pipe != null)
{
// Send the row back to the client.
SqlContext.Pipe.SendResultsRow(dataRecord);
}
}
示例4: CreateStringRecord
private static SqlDataRecord CreateStringRecord(string value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.NVarChar, MaxStringLength));
if (!string.IsNullOrWhiteSpace(value))
{
if(value.Length > MaxStringLength)
throw new SisoDbException(ExceptionMessages.SqlServerTableParams_ToLongString.Inject(MaxStringLength, value));
record.SetString(0, value);
}
else
record.SetDBNull(0);
return record;
}
示例5: CreateGuidRecord
private static SqlDataRecord CreateGuidRecord(Guid? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.UniqueIdentifier));
if (value.HasValue)
record.SetGuid(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例6: CreateDateTimeRecord
private static SqlDataRecord CreateDateTimeRecord(DateTime? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.DateTime2));
if (value.HasValue)
record.SetDateTime(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例7: CreateBooleanRecord
private static SqlDataRecord CreateBooleanRecord(bool? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.Bit));
if (value.HasValue)
record.SetBoolean(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例8: CreateFractalRecord
private static SqlDataRecord CreateFractalRecord(float? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.Real));
if (value.HasValue)
record.SetFloat(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例9: CreateLongRecord
private static SqlDataRecord CreateLongRecord(long? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.BigInt));
if (value.HasValue)
record.SetInt64(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例10: CreateIntegerRecord
private static SqlDataRecord CreateIntegerRecord(int? value)
{
var record = new SqlDataRecord(new SqlMetaData("Value", SqlDbType.Int));
if(value.HasValue)
record.SetInt32(0, value.Value);
else
record.SetDBNull(0);
return record;
}
示例11: FileStringSplitToTable
public static void FileStringSplitToTable(
SqlString fileName, SqlString delimiter)
{
string[] delimiters = new string[] { delimiter.Value };
using (System.IO.StreamReader sr = new System.IO.StreamReader(new System.IO.FileStream(
fileName.Value, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)))
{
string str;
SqlMetaData[] sqlMetadatas = null;
bool fFirst = true;
while ((str = sr.ReadLine()) != null)
{
string[] tokens = str.Split(delimiters, StringSplitOptions.None);
if (sqlMetadatas == null)
{
sqlMetadatas = new SqlMetaData[tokens.Length];
for (int iToken = 0; iToken < tokens.Length; iToken++)
{
sqlMetadatas[iToken] = new SqlMetaData("Field_" + iToken, System.Data.SqlDbType.NVarChar, -1);
}
}
#region Output fields
SqlDataRecord record = new SqlDataRecord(sqlMetadatas);
int i;
for (i = 0; i < tokens.Length; i++)
{
record.SetString(i, tokens[i]);
}
for (; i < sqlMetadatas.Length; i++) // add NULLs if need be.
{
record.SetDBNull(i);
}
if (fFirst)
{
SqlContext.Pipe.SendResultsStart(record);
fFirst = false;
}
SqlContext.Pipe.SendResultsRow(record);
#endregion
}
SqlContext.Pipe.SendResultsEnd();
}
}
示例12: SetValue
public void SetValue(ref SqlDataRecord sqlDataRecord, SqlDescriptionAttribute sqlDescription, object value,
int ordinal)
{
if (!sqlDescription.HasDbType)
{
throw new InvalidDataException("SqlDbType can not be null");
}
if (value == null)
{
sqlDataRecord.SetDBNull(ordinal);
return;
}
switch (sqlDescription.SqlDbType)
{
case SqlDbType.BigInt:
var ll = value as long?;
if (!ll.HasValue)
{
throw new Exception("Value is not BigInt");
}
sqlDataRecord.SetInt64(ordinal, ll.Value);
break;
case SqlDbType.Binary:
var bb = value as byte?;
if (!bb.HasValue)
{
throw new Exception("Value is not BigInt");
}
sqlDataRecord.SetSqlByte(ordinal, bb.Value);
break;
case SqlDbType.Bit:
var bit = value as bool?;
if (!bit.HasValue)
{
throw new Exception("Value is not Bit");
}
sqlDataRecord.SetBoolean(ordinal, bit.Value);
break;
case SqlDbType.NChar:
case SqlDbType.Char:
var chr = value as char?;
if (!chr.HasValue)
{
throw new Exception("Value is not Char");
}
sqlDataRecord.SetChar(ordinal, chr.Value);
break;
case SqlDbType.DateTime:
case SqlDbType.SmallDateTime:
case SqlDbType.Date:
case SqlDbType.DateTime2:
var dt = value as DateTime?;
if (!dt.HasValue)
{
throw new Exception("Value is not DateTime");
}
sqlDataRecord.SetDateTime(ordinal, dt.Value);
break;
case SqlDbType.Decimal:
case SqlDbType.Money:
case SqlDbType.SmallMoney:
var dc = value as decimal?;
if (!dc.HasValue)
{
throw new Exception("Value is not Decimal");
}
sqlDataRecord.SetDecimal(ordinal, dc.Value);
break;
case SqlDbType.Float:
var d = value as double?;
if (!d.HasValue)
{
throw new Exception("Value is not Double");
}
sqlDataRecord.SetDouble(ordinal, d.Value);
break;
case SqlDbType.Image:
case SqlDbType.VarBinary:
var bytes = value as byte[];
if (bytes == null)
{
throw new Exception("Value is not byte array");
}
sqlDataRecord.SetBytes(ordinal, 0, bytes, 0, bytes.Length);
break;
case SqlDbType.Int:
var integer = value as int?;
if (integer == null)
{
var ushortValue = (value as ushort?);
if (ushortValue == null)
{
throw new Exception("Value is not int or ushort");
}
integer = ushortValue.Value;
}
sqlDataRecord.SetInt32(ordinal, integer.Value);
break;
case SqlDbType.NText:
case SqlDbType.NVarChar:
//.........这里部分代码省略.........