Special requirements
A special requirement is that the user attributes customized by aspnet_Profile must be extracted. This special requirement is as follows:
To extract the user's attribute list, my machine can only access the development library and cannot access the production library. DBA is also very busy, so it takes the original data and uses the program for decomposition.
Profile (aspnet_Profile)
Field name |
Type |
Attribute |
Description |
UserId |
Uniqueidentifier |
FK: aspnet_Users.UserId |
User ID |
PropertyNames |
Ntext |
|
Attribute name |
PropertyValuesString |
Ntext |
|
String Value |
PropertyValuesBinary |
Image |
|
Binary Value |
The data looks like this:
| Propertynames |
| NID: S: 0: 3: Company: S: 3: 3: PID: S: 6: 3: TrueName: S: 9: 2: |
| Propertyvaluesstring |
| 338comw.li |
C # implementation /// <Summary>
/// Obtain the attribute value in aspnet_Profile
/// </Summary>
/// <Returns> </returns>
Private DataTable GetProfileProperty ()
{
String SQL = @ "SELECT
[Username]
, [Rolename]
, [Propertynames]
, [Propertyvaluesstring]
FROM [VUserProfile] ";
DataSet ds = DBUtility. getDataSet (SQL );
// NID, Company, PID, and TrueName are Custom User attributes.
DataTable dt = new DataTable ();
DataColumn UserName = new DataColumn ("UserName", typeof (string ));
DataColumn RoleName = new DataColumn ("RoleName", typeof (string ));
DataColumn NID = new DataColumn ("NID", typeof (string ));
DataColumn Company = new DataColumn ("Company", typeof (string ));
DataColumn PID = new DataColumn ("PID", typeof (string ));
DataColumn TrueName = new DataColumn ("TrueName", typeof (string ));
Dt. Columns. Add (UserName );
Dt. Columns. Add (RoleName );
Dt. Columns. Add (NID );
Dt. Columns. Add (Company );
Dt. Columns. Add (PID );
Dt. Columns. Add (TrueName );
For (int I = 0; I <ds. Tables [0]. Rows. Count; I ++)
{
DataRow row = ds. Tables [0]. Rows [I];
String username = row ["username"]. ToString ();
String rolename = row ["rolename"]. ToString ();
String propertynames = row ["propertynames"]. ToString (). Replace (": S :","*");
String propertyvaluesstring = row ["propertyvaluesstring"]. ToString ();
DataRow dtrow = dt. NewRow ();
Dtrow ["UserName"] = username;
Dtrow ["RoleName"] = rolename;
String [] p1 = propertynames. Split ('*');
For (int j = 0; j <p1.Length-1; j ++)
{
String [] tmp = p1 [j]. Split (':');
String [] tmp2 = p1 [j + 1]. Split (':');
String propertyname = tmp [tmp. Length-1];
String propertyvalue = propertyvaluesstring. Substring (int. Parse (tmp2 [0]), int. Parse (tmp2 [1]);
Dtrow [propertyname] = propertyvalue;
}
Dt. Rows. Add (dtrow );
}
Return dt;
}
Effect
| UserName |
RoleName |
NID |
CompanyID |
PID |
TrueName |
| Leex |
Customer Service |
800 |
C1 |
201 |
Li X |
| Leey |
Finance |
801 |
C2 |
202 |
Li Y |
| Leez |
Agent |
801 |
C3 |
203 |
Li Z |