当前位置: 首页>>代码示例>>C#>>正文


C# SqlDatabase.ExecuteScalar方法代码示例

本文整理汇总了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"));
			}
		}
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:27,代码来源:DataInstrumentationListenerFixture.cs

示例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;
 }
开发者ID:the0ther,项目名称:how2www.info,代码行数:8,代码来源:Utility.cs

示例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 ) );
        }
开发者ID:the0ther,项目名称:how2www.info,代码行数:9,代码来源:Utility.cs

示例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;
 }
开发者ID:the0ther,项目名称:how2www.info,代码行数:10,代码来源:Utility.cs

示例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);
        }
开发者ID:JeyssonRamirez,项目名称:Freelance,代码行数:11,代码来源:NalyerRoleProvider.cs

示例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;
 }
开发者ID:the0ther,项目名称:how2www.info,代码行数:11,代码来源:Utility.cs

示例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;
 }
开发者ID:the0ther,项目名称:how2www.info,代码行数:11,代码来源:Utility.cs

示例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;
        }
开发者ID:tsubik,项目名称:SFASystem,代码行数:12,代码来源:CityDB.cs

示例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;
        }
开发者ID:tsubik,项目名称:SFASystem,代码行数:12,代码来源:RoleDB.cs

示例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;
        }
开发者ID:JeyssonRamirez,项目名称:NLayer,代码行数:13,代码来源:NlayerProfileProvider.cs

示例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;
        }
开发者ID:cveggalam,项目名称:Restaurant,代码行数:14,代码来源:GlobalClass.cs

示例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;
        }
开发者ID:tsubik,项目名称:SFASystem,代码行数:15,代码来源:TerritoryDB.cs

示例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;
        }
开发者ID:liveevil,项目名称:TravelMS,代码行数:16,代码来源:LoginDALayer.cs

示例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;
        }
开发者ID:liveevil,项目名称:TravelMS,代码行数:16,代码来源:LoginDALayer.cs

示例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;
        }
开发者ID:tsubik,项目名称:SFASystem,代码行数:16,代码来源:ContactDB.cs


注:本文中的Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase.ExecuteScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。