本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteScalar方法的典型用法代码示例。如果您正苦于以下问题:C# SqlDatabase.ExecuteScalar方法的具体用法?C# SqlDatabase.ExecuteScalar怎么用?C# SqlDatabase.ExecuteScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase
的用法示例。
在下文中一共展示了SqlDatabase.ExecuteScalar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoLotsOfConnectionFailures
public void DoLotsOfConnectionFailures()
{
int numberOfEvents = 50;
using (WmiEventWatcher eventListener = new WmiEventWatcher(numberOfEvents))
{
SqlDatabase db = new SqlDatabase("BadConnectionString");
DataInstrumentationListener listener = new DataInstrumentationListener("foo", true, true, true);
DataInstrumentationListenerBinder binder = new DataInstrumentationListenerBinder();
binder.Bind(db.GetInstrumentationEventProvider(), listener);
for (int i = 0; i < numberOfEvents; i++)
{
try
{
db.ExecuteScalar(CommandType.Text, "Select count(*) from Region");
}
catch { }
}
eventListener.WaitForEvents();
Assert.AreEqual(numberOfEvents, eventListener.EventsReceived.Count);
Assert.AreEqual("ConnectionFailedEvent", eventListener.EventsReceived[0].ClassPath.ClassName);
Assert.AreEqual("foo", eventListener.EventsReceived[0].GetPropertyValue("InstanceName"));
Assert.AreEqual(db.ConnectionStringWithoutCredentials, eventListener.EventsReceived[0].GetPropertyValue("ConnectionString"));
}
}
示例2: CurrectWeek
public static int CurrectWeek()
{
SqlDatabase db = new SqlDatabase( connString );
DbCommand command = db.GetStoredProcCommand( "getWeekNr" );
command.CommandType = CommandType.StoredProcedure;
//the +1 below is to correct for an apparent off-by-one error in the stored procedure
return Convert.ToInt32( db.ExecuteScalar( command ) ) + 1;
}
示例3: CurrectWeekStartDate
public static DateTime CurrectWeekStartDate( int currentWeek )
{
SqlDatabase db = new SqlDatabase( connString );
DbCommand command = db.GetStoredProcCommand( "smWkNmStr" );
command.CommandType = CommandType.StoredProcedure;
db.AddInParameter( command, "@week_no", DbType.Int32, currentWeek );
return Convert.ToDateTime( db.ExecuteScalar( command ) );
}
示例4: GetJobEndDate
public static DateTime GetJobEndDate(int jobId)
{
SqlDatabase db = new SqlDatabase(connString);
DbCommand command = db.GetSqlStringCommand("SELECT currentEndDate FROM AllOpenJobs WHERE JobId=" + jobId);
DateTime retval = DateTime.MinValue;
object obj = db.ExecuteScalar(command);
if (obj != DBNull.Value)
retval = Convert.ToDateTime(obj);
return retval;
}
示例5: IsUserInRole
public override bool IsUserInRole(string username, string roleName)
{
SqlDatabase sqlDatabase = new SqlDatabase(_connectionString);
DbCommand dbCommand = sqlDatabase.GetStoredProcCommand("adm.SCISP_EstaElUsuarioEnElRol");
sqlDatabase.AddInParameter(dbCommand, "Aplicacion", DbType.String, _applicationName);
sqlDatabase.AddInParameter(dbCommand, "Login", DbType.String, username);
sqlDatabase.AddInParameter(dbCommand, "Rol", DbType.String, roleName);
return (bool) sqlDatabase.ExecuteScalar(dbCommand);
}
示例6: GetClientIdForJob
public static int GetClientIdForJob(int jobId)
{
int retval = -1;
SqlDatabase db = new SqlDatabase(connString);
DbCommand command = db.GetSqlStringCommand("SELECT ClientId FROM AllOpenJobs WHERE JobId=" + jobId);
command.CommandType = CommandType.Text;
object obj = db.ExecuteScalar(command);
if (obj != DBNull.Value)
retval = Convert.ToInt32(obj);
return retval;
}
示例7: GetDeptIdForUser
public static int GetDeptIdForUser(int userId)
{
int retval = -1;
SqlDatabase db = new SqlDatabase(connString);
DbCommand command = db.GetSqlStringCommand("SELECT DeptId FROM AllocableUsers WHERE UserId=" + userId);
command.CommandType = CommandType.Text;
object obj = db.ExecuteScalar(command);
if (obj != DBNull.Value)
retval = Convert.ToInt32(obj);
return retval;
}
示例8: InsertCity
public static City InsertCity(City city)
{
string sqlQuery = "INSERT INTO City(Name) " +
" VALUES(@Name);SELECT @@Identity";
Database db = new SqlDatabase(DBHelper.GetConnectionString());
DbCommand dbCommand = db.GetSqlStringCommand(sqlQuery);
db.AddInParameter(dbCommand, "Name", DbType.String, city.Name);
city.CityID = Convert.ToInt32(db.ExecuteScalar(dbCommand));
return city;
}
示例9: InsertRole
public static Role InsertRole(Role role)
{
string sqlQuery = "INSERT INTO ROLE(Name) VALUES(@Name);SELECT @@Identity";
Database db = new SqlDatabase(DBHelper.GetConnectionString());
DbCommand dbCommand = db.GetSqlStringCommand(sqlQuery);
db.AddInParameter(dbCommand, "Name", DbType.String, role.Name);
role.RoleID = Convert.ToInt32(db.ExecuteScalar(dbCommand));
return role;
}
示例10: DeleteInactiveProfiles
public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption,
DateTime userInactiveSinceDate)
{
SqlDatabase sqlDatabase = new SqlDatabase(_connectionString);
DbCommand dbCommand = sqlDatabase.GetStoredProcCommand("adm.NlayerSP_EliminarPerfilesInactivos");
sqlDatabase.AddInParameter(dbCommand, "Aplicacion", DbType.String, _applicationName);
sqlDatabase.AddInParameter(dbCommand, "UltimaActividad", DbType.DateTime, userInactiveSinceDate);
int deleteCount = (int) sqlDatabase.ExecuteScalar(dbCommand);
return deleteCount;
}
示例11: GetCurrentDateTime
public static DateTime GetCurrentDateTime()
{
DateTime dt = DateTime.MinValue;
SqlDatabase objSqlDatabase = new SqlDatabase(_ConStr);
try
{
string commandText = "SELECT GETDATE() AS Today ";
dt = (DateTime)objSqlDatabase.ExecuteScalar(System.Data.CommandType.Text, commandText);
}
catch (SqlException)
{ }
return dt;
}
示例12: InsertTerritory
public static Territory InsertTerritory(Territory territory)
{
string sqlQuery = "INSERT INTO Territory(ParentTerritoryID,FullDescription,Name) " +
" VALUES(@ParentTerritoryID,@FullDescription,@Name);SELECT @@Identity";
Database db = new SqlDatabase(DBHelper.GetConnectionString());
DbCommand dbCommand = db.GetSqlStringCommand(sqlQuery);
db.AddInParameter(dbCommand, "ParentTerritoryID", DbType.Int32, territory.ParentTerritoryID);
db.AddInParameter(dbCommand, "FullDescription", DbType.String, territory.FullDescription);
db.AddInParameter(dbCommand, "Name", DbType.String, territory.Name);
territory.TerritoryID = Convert.ToInt32(db.ExecuteScalar(dbCommand));
return territory;
}
示例13: LoginUserDAL
public static bool LoginUserDAL(LoginModel userData)
{
SqlDatabase travelMSysDB = new SqlDatabase(ConnString.DBConnectionString);// (@"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\TravelMS_Sep16.mdf;Integrated Security=True");
SqlCommand selectCmmnd = new SqlCommand("SELECT [Password] FROM EMPLOYEES WHERE [User_ID][email protected]_ID");
selectCmmnd.CommandType = CommandType.Text;
selectCmmnd.Parameters.AddWithValue("@User_ID", userData.User_ID);
object pHash = travelMSysDB.ExecuteScalar(selectCmmnd);
if (!(pHash == null))
if (pHash.ToString().Equals(userData.Password))
return true;
return false;
}
示例14: LoginAgentDAL
public static bool LoginAgentDAL(LoginModel userData)
{
SqlDatabase travelMSysDB = new SqlDatabase(ConnString.DBConnectionString);
SqlCommand selectCmmnd = new SqlCommand("SELECT [Password] FROM AGENTS WHERE [Agent_ID][email protected]_ID");
selectCmmnd.CommandType = CommandType.Text;
selectCmmnd.Parameters.AddWithValue("@User_ID", userData.User_ID);
object pHash = travelMSysDB.ExecuteScalar(selectCmmnd);
if (!(pHash == null))
if (pHash.ToString().Equals(userData.Password))
return true;
return false;
}
示例15: InsertContact
public static Contact InsertContact(Contact contact)
{
string sqlQuery = "INSERT INTO Contact(FirstName,LastName,Email,Phone) " +
" VALUES(@FirstName,@LastName,@Email,@Phone);SELECT @@Identity";
Database db = new SqlDatabase(DBHelper.GetConnectionString());
DbCommand dbCommand = db.GetSqlStringCommand(sqlQuery);
db.AddInParameter(dbCommand, "FirstName", DbType.String, contact.FirstName);
db.AddInParameter(dbCommand, "LastName", DbType.String, contact.LastName);
db.AddInParameter(dbCommand, "Email", DbType.String, contact.Email);
db.AddInParameter(dbCommand, "Phone", DbType.String, contact.Phone);
contact.ContactID = Convert.ToInt32(db.ExecuteScalar(dbCommand));
return contact;
}