本文整理汇总了C#中Utilities.SQL.SQLHelper.ExecuteBulkCopy方法的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper.ExecuteBulkCopy方法的具体用法?C# SQLHelper.ExecuteBulkCopy怎么用?C# SQLHelper.ExecuteBulkCopy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities.SQL.SQLHelper
的用法示例。
在下文中一共展示了SQLHelper.ExecuteBulkCopy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BulkCopy
public void BulkCopy()
{
Guid TempGuid=Guid.NewGuid();
List<BulkCopyObject> Objects = new List<BulkCopyObject>();
for (int x = 0; x < 100; ++x)
{
BulkCopyObject TempObject = new BulkCopyObject();
TempObject.BigIntValue = 12345;
TempObject.BitValue = true;
TempObject.DateTimeValue = new DateTime(1999, 12, 31);
TempObject.DecimalValue = 1234.5678m;
TempObject.FloatValue = 12345.6534f;
TempObject.GUIDValue = TempGuid;
TempObject.ID = x+1;
TempObject.StringValue1 = "Test String";
TempObject.StringValue2 = "Test String";
Objects.Add(TempObject);
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.ExecuteBulkCopy(Objects.ToDataTable(),"TestTable");
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.ExecuteReader();
bool Inserted=false;
while (Helper.Read())
{
Inserted=true;
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", ""));
Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0));
Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false));
Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0));
Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0));
Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty));
Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now));
}
if(!Inserted)
{
Assert.Fail("Nothing was inserted");
}
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT COUNT(*) as [ItemCount] FROM TestTable", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.ExecuteReader();
if (Helper.Read())
{
Assert.Equal(100, Helper.GetParameter<int>("ItemCount", 0));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
}