I am using WebMatrix to create a table in my user database.
My tutorial says to use the BOOLEAN data type for the field that determines whether or not the user's registration is active, because it allows the field to be true or false. BOOLEAN is not an option.
What can I use instead to achieve the same result?
Please feel free to ask for clarification. Any help is much appreciated. Even suggestions for other tutorials on creating a user registration / member system would be great. Thank you!
The answer you are looking for is "bit" and the default value is 0 (zero) this will be interpreted as false by MS SQL Server 2012. To say it another way the "bool" value in Webmatrix equates to a "bit" value in MS SQL Server 2012.
// on the webmatrix side of things
Int UserID = 0; // the users id (usually int)
bool allowed = false;
// the database needs at least 2 fields
int UserID;
bit Allowed;
var db = Database.Open("TheDatabase");
// don't forget to set this up in your web.config file.
var TestRecord = db.QuerySingle("SELECT * FROM webpages_Membership WHERE UserID=#0", UserID );
allowed TestRecord.Allowed;
db.close();
This is just a ruff sketch of how to accomplish this... hope it helps
Related
I'm trying to access entities (Contacts) in a HTML WebResource inside an Account formular in Microsoft Dynamics. However I cannot figure out how to get the record GUID (accountId) from the PageContext. It tells me the entityId is undefined.
I'm trying to replace this deprechated code line:
const accountId = parent.Xrm.Page.data.entity.getId();
I've been trying to use
const pageContext = window.parent.Xrm.Utility.getPageContext();
but the attributes are almost all null or undefined including the entityId. All it tells me is that I'm in an account record. See image. https://imgur.com/a/oeA1SOz
Thanks for any help
Yes is possible, you were close in your second attempt.
This will return the id:
var id = parent.Xrm.Utility.getPageContext().input.entityId.replace("{", '').replace("}", '');
From Microsoft docs:
Pass parameters to HTML web resources
although I have searched in various resources I cannot understand how to correctly insert the ‘status’ column, I will explain better.
I have two sql tables:
From the gestionepc form using dropdown, I can select the numerazionecolumn of thenumerazionitable and so far everything works without problems. However, I need to insert the “status” column on thenumerazionitable so that if I use a record in thenumerazionicolumn, itsstatus` must automatically change to “Not active” as it is already used. For my project, it is a requirement derived from the fact that I have various groups of user permissions and various authorizations.
In practice, I'm very confused about how to insert the status column (type of column, default value, storage also on the MySQL database and initialize it) and on how to make it work through the code (perhaps using afterSave and beforeUpdate).
I read Active Record from Guide Yii2 but I don’t understand.
I modify table numerazioni in this mode:
And I try this in model Numerazioni
const STATUS_INDISPONIBILE = 'Indisponibile';
const STATUS_DISPONIBILE = 'Disponibile';
public function setStatusnumerazione()
{
if (\app\models\Gestionepc::find()->where(!isEmpty('numerazioni_id'))) {
$this->statusnumerazione = self::STATUS_INDISPONIBILE;
}
else {
$this->statusnumerazione = self::STATUS_DISPONIBILE;
}
}
But not working. Thanks in advance.
We have a system that stores the username/password as plain text. I have been asked to covert this to Membership.
I'd like a SQL function to convert the plain text password into .NET Membership Hashed password. The only HashBytes function I found doesn't even come close to what I see in the .NET Membership table.
I am desperate. Please help.
I learnt that you cannot generate the same HASH algorithm in T-SQL and the best way is to simple read your basic table to the ASP.net side, then call the Membership Script to insert users. This cuts down on time as well.
DataSet dtData = DivDatabase.ExecuteSQLString("SELECT * FROM Users");
foreach (DataRow row in dtData.Tables[0].Rows)
{
MembershipUser mUser = null;
mUser = Membership.GetUser(row["Username"].ToString());
if (mUser == null)
{
mUser = Membership.CreateUser(row["Username"].ToString(), row["Password"].ToString(), row["Email"].ToString() );
}
}
I first check if the userName is not in the system already. This is because I had duplicating usernames and I wanted to eliminate that. For additional information from the old table that doesn't exist in the Membership tables, we agreed with the senior management that we are not going to use the Membership Profile as it's not easy to write queries against this. But I have added sample code for reference.
var profile = System.Web.Profile.ProfileBase.Create(row["Username"].ToString());
profile.SetPropertyValue("FirstName", row["FirstName"].ToString());
profile.SetPropertyValue("LastName", row["LastName"].ToString());
profile.Save();
I hope you find this useful.
I am modifying my PHP network's code to have "user roles" like wordpress here is my plan so far
0 = registred non email verified user
1 = registed and verified email
2 = moderator
3-9 = nothing yet
10= admin
In my PHP code I will use an array like this that will set what a role number does.
$user_role['10']
I was thinking of storing which value a user has in my mysql DB, would this be the best way to store the 10 different role options as an enum or is there a better way or faster way? I read that enum is not the fastest sometimes.
enum('0','1','2','3','4','5','6','7','8','9','10')
I guess INT or TINYINT is enough to store user level (role). Also you may consider multiplting the numbers by 10, so you'll have a space to add more levels in future.
Use bitmasks for permissions / user levels.
See example.
I've been using Linq to SQL for some time now and I find it to be really helpful and easy to use. With other ORM tools I've used in the past, the entity object filled from the database normally has a property indicating the length of the underlying data column in the database. This is helpful in databinding situations where you can set the MaxLength property on a textbox, for example, to limit the length of input entered by the user.
I cannot find a way using Linq to SQL to obtain the length of an underlying data column. Does anyone know of a way to do this? Help please.
Using the LINQ ColumnAttribute to Get Field Lengths from your Database :
http://www.codeproject.com/KB/cs/LinqColumnAttributeTricks.aspx
Thanks. Actually both of these answers seem to work. Unfortunately, they seem to look at the Linq attributes generated when the code-generation was done. Although that would seem to be the right thing to do, in my situation we sell software products and occasionally the customer will expand some columns lengths to accommodate their data. Thus, the length of the field as reported using this technique may not always reflect the true length of the underlying data column. Ah well, not Linq to SQL's fault, is it? :)
Thanks for the quick answers!
If you need to know the exact column length you can resort to the System.Data classes themselves. Something a bit like this:
var context = new DataContextFromSomewhere();
var connection = context.Connection;
var command = connection.CreateCommand( "SELECT TOP 1 * FROM TableImInterestedIn" );
var reader = command.ExecuteReader();
var table = reader.GetSchemaTable();
foreach( var column in table.Columns )
{
Console.WriteLine( "Length: {0}", column.MaxLength );
}