本文整理汇总了C#中DbCommand.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# DbCommand.ExecuteScalar方法的具体用法?C# DbCommand.ExecuteScalar怎么用?C# DbCommand.ExecuteScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbCommand
的用法示例。
在下文中一共展示了DbCommand.ExecuteScalar方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetForumBreadCrumbs
public static string GetForumBreadCrumbs(int forumID, DbCommand cmd)
{
string retval = "";
//to save performance and prevent close/reopn connection a thousand times we do this
bool openConn = (cmd.Connection.State == ConnectionState.Open);
if (!openConn) cmd.Connection.Open();
//get the forum title
cmd.CommandText = "SELECT Title FROM Forums WHERE ForumID=" + forumID;
string forumTitle = cmd.ExecuteScalar().ToString();
retval = "<a href=\"" + GetForumURL(forumID, forumTitle) + "\">" + forumTitle + "</a>";
//check if it's a subforum
cmd.CommandText = "SELECT ParentForumID FROM ForumSubforums WHERE SubForumID=" + forumID;
object res = cmd.ExecuteScalar();
if (res != null) retval = GetForumBreadCrumbs(Convert.ToInt32(res), cmd) + " - " + retval;
if (!openConn) cmd.Connection.Close();
return retval;
}
示例2: ExecuteScalar
public override object ExecuteScalar(DbCommand command)
{
if (_Connection.State != System.Data.ConnectionState.Open) _Connection.Open();
command.Connection = _Connection;
command.Transaction = _Transaction;
return command.ExecuteScalar();
}
示例3: Count
//Count statement
public int Count(DbCommand query)
{
int Count = -1;
//Open Connection
if (this.OpenConnection() != null)
{
//Create Mysql Command
query.Connection = connection;
//ExecuteScalar will return one value
Count = int.Parse(query.ExecuteScalar() + "");
//close Connection
this.CloseConnection();
return Count;
}
else
{
return Count;
}
}