Extract user attributes customized by aspnet_Profile (C # implementation)

Source: Internet
Author: User

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

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.