本文整理汇总了C#中Utilities.SQL.SQLHelper.Read方法的典型用法代码示例。如果您正苦于以下问题:C# SQLHelper.Read方法的具体用法?C# SQLHelper.Read怎么用?C# SQLHelper.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utilities.SQL.SQLHelper
的用法示例。
在下文中一共展示了SQLHelper.Read方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Delete
public void Delete()
{
using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("","Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false",CommandType.Text))
{
Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
TestObject.Map(x => x.ID, "ID_")
.Map(x => x.StringValue, "StringValue_")
.Map(x => x.FloatValue, "FloatValue_")
.Map(x => x.BoolValue, "BoolValue_")
.Map(x => x.LongValue, "LongValue_")
.Map(x => x.StringMaxValue, "StringMaxValue_");
Utilities.Random.Random Rand = new Utilities.Random.Random();
ObjectClass1 TempObject = new ObjectClass1();
TempObject.StringValue = "Test";
TempObject.BoolValue = false;
TempObject.FloatValue = 1.5f;
TempObject.LongValue = 12;
TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
Helper2.Save<ObjectClass1, int>(TempObject);
Assert.Equal(1, Helper2.Delete<ObjectClass1>(TempObject));
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(0, Helper.GetParameter<int>("ItemCount", -1));
}
else
{
Assert.False(true,"Nothing was inserted");
}
}
}
}
示例2: Update
public void Update()
{
using (Utilities.SQL.SQLHelper Helper2 = new Utilities.SQL.SQLHelper("", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Mapping<ObjectClass1> TestObject = Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable", "ID_");
TestObject.Map(x => x.ID, "ID_")
.Map(x => x.StringValue, "StringValue_")
.Map(x => x.FloatValue, "FloatValue_")
.Map(x => x.BoolValue, "BoolValue_")
.Map(x => x.LongValue, "LongValue_")
.Map(x => x.StringMaxValue, "StringMaxValue_");
Utilities.Random.Random Rand = new Utilities.Random.Random(12346);
ObjectClass1 TempObject = new ObjectClass1();
TempObject.StringValue = "Test";
TempObject.BoolValue = false;
TempObject.FloatValue = 1.5f;
TempObject.LongValue = 12;
TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
TempObject.ID = Helper2.Insert<ObjectClass1, int>(TempObject);
Rand = new Utilities.Random.Random(12345);
TempObject.StringValue = "Test String";
TempObject.BoolValue = true;
TempObject.FloatValue = 1234.5f;
TempObject.LongValue = 12345;
TempObject.StringMaxValue = Rand.Next<string>(new RegexStringGenerator(6000));
Helper2.Update(TempObject);
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();
if (Helper.Read())
{
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", ""));
Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0));
Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false));
Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0));
Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0));
Assert.Equal(TempObject.StringMaxValue, Helper.GetParameter<string>("StringMaxValue_", ""));
}
else
{
Assert.False(true,"Nothing was inserted");
}
}
}
}
示例3: 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");
}
}
}
示例4: Save
public void Save()
{
Utilities.SQL.SQLHelper.Database("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false");
Utilities.SQL.SQLHelper.Map<ObjectClass1>("TestTable","ID_")
.Map(x => x.ID, "ID_")
.Map(x => x.StringValue, "StringValue_")
.Map(x => x.FloatValue, "FloatValue_")
.Map(x => x.BoolValue, "BoolValue_")
.Map(x => x.LongValue, "LongValue_");
ObjectClass1 TempObject = new ObjectClass1();
using (Utilities.SQL.SQLHelper ORM = new Utilities.SQL.SQLHelper())
{
TempObject.StringValue = "Test";
TempObject.BoolValue = false;
TempObject.FloatValue = 1.5f;
TempObject.LongValue = 12;
ORM.Save<ObjectClass1, int>(TempObject);
TempObject.StringValue = "Test String";
TempObject.BoolValue = true;
TempObject.FloatValue = 1234.5f;
TempObject.LongValue = 12345;
ORM.Save<ObjectClass1,int>(TempObject);
}
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();
if (Helper.Read())
{
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue_", ""));
Assert.Equal(1234.5f, Helper.GetParameter<float>("FloatValue_", 0));
Assert.Equal(true, Helper.GetParameter<bool>("BoolValue_", false));
Assert.Equal(12345, Helper.GetParameter<long>("LongValue_", 0));
Assert.Equal(TempObject.ID, Helper.GetParameter<int>("ID_", 0));
}
else
{
Assert.False(true,"Nothing was inserted");
}
}
}
示例5: Update
public void Update()
{
Guid TempGuid = Guid.NewGuid();
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.AddParameter<string>("@StringValue1", "Test");
Helper.AddParameter<string>("@StringValue2", "Test");
Helper.AddParameter<long>("@BigIntValue", 123);
Helper.AddParameter<bool>("@BitValue", false);
Helper.AddParameter<decimal>("@DecimalValue", 1234);
Helper.AddParameter<float>("@FloatValue", 12345);
Helper.AddParameter<Guid>("@GUIDValue", Guid.NewGuid());
Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 1, 1));
Helper.ExecuteNonQuery();
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("update TestTable set [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.AddParameter<string>("@StringValue1", "Test String");
Helper.AddParameter<string>("@StringValue2", "Test String");
Helper.AddParameter<long>("@BigIntValue", 12345);
Helper.AddParameter<bool>("@BitValue", true);
Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m);
Helper.AddParameter<float>("@FloatValue", 12345.6534f);
Helper.AddParameter<Guid>("@GUIDValue", TempGuid);
Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31));
Helper.ExecuteNonQuery();
}
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();
if (Helper.Read())
{
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));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
}
示例6: Delete
public void Delete()
{
Guid TempGuid = Guid.NewGuid();
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.AddParameter<string>("@StringValue1", "Test String");
Helper.AddParameter<string>("@StringValue2", "Test String");
Helper.AddParameter<long>("@BigIntValue", 12345);
Helper.AddParameter<bool>("@BitValue", true);
Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m);
Helper.AddParameter<float>("@FloatValue", 12345.6534f);
Helper.AddParameter<Guid>("@GUIDValue", TempGuid);
Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31));
Helper.ExecuteNonQuery();
}
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.AddParameter<int>("@ID", 1);
Helper.ExecuteNonQuery();
}
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();
if (Helper.Read())
{
Assert.Fail("Nothing was deleted");
}
}
}
示例7: CommandInsertNullString
public void CommandInsertNullString()
{
Guid TempGuid = Guid.NewGuid();
Utilities.SQL.Command TempCommand = new Utilities.SQL.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
{
Helper.ExecuteNonQuery();
}
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();
if (Helper.Read())
{
Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", ""));
Assert.Equal("This is a null string", Helper.GetParameter<string>("StringValue2", "This is a null string"));
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));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
}
示例8: CachedQuery
public void CachedQuery()
{
Guid TempGuid = Guid.NewGuid();
for (int x = 0; x < 100; ++x)
{
using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", CommandType.Text))
{
Helper.AddParameter<string>("@StringValue1", "Test String")
.AddParameter<string>("@StringValue2", "Test String")
.AddParameter<long>("@BigIntValue", 12345)
.AddParameter<bool>("@BitValue", true)
.AddParameter<decimal>("@DecimalValue", 1234.5678m)
.AddParameter<float>("@FloatValue", 12345.6534f)
.AddParameter<Guid>("@GUIDValue", TempGuid)
.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31))
.ExecuteNonQuery();
}
}
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(Cache: true);
int Count=0;
while (Helper.Read())
{
++Count;
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));
}
Assert.Equal(100, Count);
}
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(Cache: true);
int Count = 0;
while (Helper.Read())
{
++Count;
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));
}
Assert.Equal(100, Count);
}
}
示例9: Delete
public void Delete()
{
using (Mapping<ObjectClass1> TestObject = new Mapping<ObjectClass1>("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false", "TestTable", "ID_"))
{
TestObject.Map(x => x.ID, "ID_")
.Map(x => x.StringValue, "StringValue_", 100)
.Map(x => x.FloatValue, "FloatValue_")
.Map(x => x.BoolValue, "BoolValue_")
.Map(x => x.LongValue, "LongValue_");
ObjectClass1 TempObject = new ObjectClass1();
TempObject.StringValue = "Test";
TempObject.BoolValue = false;
TempObject.FloatValue = 1.5f;
TempObject.LongValue = 12;
TestObject.Save<int>(TempObject);
Assert.Equal(1, TestObject.Delete(TempObject));
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(0, Helper.GetParameter<int>("ItemCount", -1));
}
else
{
Assert.Fail("Nothing was inserted");
}
}
}
}