本文整理汇总了C#中System.Data.SqlClient.SqlCommand.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.GetValue方法的具体用法?C# SqlCommand.GetValue怎么用?C# SqlCommand.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.GetValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestInsert
public void TestInsert()
{
var students = StudentHelper.CreateSample(10).ToArray();
using (var sqlConnection = DatabaseHelper.OpenSqlConnection(DatabaseName))
{
var sqlUpserter = new SqlUpserter<Student>(StudentMapper, TableName, students);
sqlUpserter.Execute(sqlConnection);
var selectText = "SELECT " + string.Join(",", StudentMapper.Columns.Select(column => column.Name)) +
" FROM " + TableName;
var reader = new SqlCommand(selectText, sqlConnection).ExecuteReader();
var row = 0;
while (reader.Read())
{
var student = students[row];
for (var column = 0; column < reader.FieldCount; column++)
{
var expected = StudentMapper.GetValueAt(column, student);
var actual = reader.GetValue(column);
Assert.AreEqual(expected, actual);
}
row++;
}
}
}
示例2: GetDateModifiedUtc
public DateTime GetDateModifiedUtc(int id, string filename)
{
//this.FireAuthorizeEvent(id);
SqlConnection connectionObj = this.GetConnectionObj();
connectionObj.Open();
DateTime result;
using (connectionObj)
{
SqlDataReader sqlDataReader = new SqlCommand(this.modifiedDateQuery, connectionObj)
{
Parameters =
{
CreateParameter("id", id, SqlDbType.Int),
CreateParameter("name", filename, SqlDbType.NVarChar)
}
}.ExecuteReader();
using (sqlDataReader)
{
if (!sqlDataReader.Read())
{
result = DateTime.MinValue;
return result;
}
for (var i = 0; i < sqlDataReader.FieldCount; i++)
{
if (!sqlDataReader.IsDBNull(i) && sqlDataReader.GetValue(i) is DateTime)
{
result = (DateTime)sqlDataReader.GetValue(i);
return result;
}
}
}
}
return DateTime.MinValue;
}
示例3: TestUpdate
public void TestUpdate()
{
var students = StudentHelper.CreateSample(10).ToArray();
using (var sqlConnection = DatabaseHelper.OpenSqlConnection(DatabaseName))
{
var sqlUpserter1 = new SqlUpserter<Student>(StudentMapper, TableName, students);
sqlUpserter1.Execute(sqlConnection);
var expectedChanges = 0;
foreach (var student in students)
{
if (student.Id%2 == 0)
{
student.FirstName = student.FirstName + "_Changed";
expectedChanges++;
}
}
var sqlUpserter2 = new SqlUpserter<Student>(StudentMapper, TableName, students);
sqlUpserter2.Execute(sqlConnection);
var selectText = "SELECT " + string.Join(",", StudentMapper.Columns.Select(column => column.Name)) +
" FROM " + TableName;
var reader = new SqlCommand(selectText, sqlConnection).ExecuteReader();
var row = 0;
var currentChanges = 0;
while (reader.Read())
{
var student = students[row];
for (var column = 0; column < reader.FieldCount; column++)
{
var expected = StudentMapper.GetValueAt(column, student);
var actual = reader.GetValue(column);
if (actual.ToString().EndsWith("_Changed"))
{
currentChanges++;
}
Assert.AreEqual(expected, actual);
}
row++;
}
Assert.AreEqual(expectedChanges, currentChanges);
}
}
示例4: getDataAry
public virtual object[] getDataAry(string argString)
{
this.rState = 0;
string cmdText = argString;
object[] objArray = null;
try
{
SqlConnection connection = new SqlConnection(this.connStr);
connection.Open();
SqlDataReader reader = new SqlCommand(cmdText, connection).ExecuteReader();
int fieldCount = reader.FieldCount;
object[,] objArray2 = null;
while (reader.Read())
{
objArray2 = new object[fieldCount, 2];
for (int i = 0; i < fieldCount; i++)
{
objArray2[i, 0] = reader.GetName(i);
objArray2[i, 1] = reader.GetValue(i);
}
objArray = cls.mergeAry(objArray, objArray2);
}
reader.Close();
connection.Close();
}
catch (Exception exception)
{
this.rState = 1;
objArray = null;
this.eMessage = exception.Message;
}
return objArray;
}
示例5: cbOrder_SelectedIndexChanged
private void cbOrder_SelectedIndexChanged(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(MainForm.STRCONN))
{
connection.Open();
OrderBy orderBy = (OrderBy)cbOrderBy.SelectedItem;
string q = String.Format("SELECT Country,League,Season{0} FROM dbo.Leagues ORDER BY {1} {2}",
orderBy.SelectCol == "" ? "" : "," + orderBy.SelectCol, orderBy.OrderCol, cbOrderDir.SelectedItem);
LeaguesKey lKey;
lbLeagues.Items.Clear();
using (SqlDataReader reader = new SqlCommand(q, connection).ExecuteReader())
{
while (reader.Read())
{
lKey = new LeaguesKey();
lKey.Country = reader.GetString(0);
lKey.League = reader.GetString(1);
lKey.Season = reader.GetString(2);
if (reader.FieldCount >= 4) lKey.ExtraCol = reader.GetValue(3);
lbLeagues.Items.Add(lKey);
}
}
}
}