Console.WriteLine("Result using a SQL statement: {0}", namedDB.ExecuteScalar(sqlCmd).ToString());
protected void btnClick_Click(object sender, EventArgs e) { //// Resolve the default Database object from the container. //// The actual concrete type is determined by the configuration settings. //Database defaultDB = EnterpriseLibraryContainer.Current.GetInstance<Database>(); // Resolve a Database object from the container using the connection string name. Database namedDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("grammart"); // Resolve a SqlDatabase object from the container using the default database. SqlDatabase sqlServerDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("grammart") as SqlDatabase; // Assume the method GetConnectionString exists in your application and // returns a valid connection string. string myConnectionString =GetConnectionString(); SqlDatabase sqlDatabase = new SqlDatabase(myConnectionString); string sUser = txtUserId.Text; string pass = txtPassword.Text; using (DbCommand sqlCmd = namedDB.GetSqlStringCommand("select count(UserID) as UserID from M_User where UserID= '" + sUser + "'and password = '" + pass + "'")) { // Call the ExecuteScalar method of the command. Console.WriteLine("Result using a SQL statement: {0}", namedDB.ExecuteScalar(sqlCmd).ToString()); } } private string GetConnectionString() { Database namedDB = DatabaseFactory.CreateDatabase("grammart"); return namedDB.ConnectionString; //throw new NotImplementedException(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)