Use the gridview to list the user information stored by the profile, such as the company name!

Source: Internet
Author: User

I believe many people use profile to store user information, such as company names. However, it is very difficult to list user information in the background. Please try my method.

1. Create a view in the database: view_profile
Select DBO. aspnet_users.applicationid, DBO. aspnet_users.username,
DBO. aspnet_profile.propertynames, DBO. aspnet_profile.propertyvaluesstring,
DBO. aspnet_profile.propertyvaluesbinary
From DBO. aspnet_profile inner join
DBO. aspnet_users on DBO. aspnet_profile.userid = DBO. aspnet_users.userid

2. Create a stored procedure in the database: proc_profile_getprofiles
Create procedure DBO. proc_profile_getprofiles
@ Applicationname nvarchar (256)
As
Begin
Declare @ applicationid uniqueidentifier
Select @ applicationid = NULL
Select @ applicationid = applicationid from DBO. aspnet_applications where lower (@ applicationname) = loweredapplicationname
If (@ applicationid is null)
Return

Select username, propertynames, propertyvaluesstring, propertyvaluesbinary
From DBO. view_profile
Where applicationid = @ applicationid

End

 

3. create a new class: qwpusercontroller
public class qwpusercontroller
{< br> Public static list getusers ()
{< br> type = httpcontext. current. profile. getType ();
database DB = databasefactory. createdatabase ();
dbcommand = dB. getstoredproccommand ("proc_profile_getprofiles");
dB. addinparameter (dbcommand, "applicationname", dbtype. string, profilemanager. provider. applicationname);
sqldatareader reader1 = (sqldatareader) dB. executereader (dbcommand);

List <profilebase> List = NULL;
If (reader1.hasrows)
List = new list <profilebase> ();

While (reader1.read ())
{
String username = NULL;
String [] textarray1 = NULL;
String text1 = NULL;
Byte [] buffer1 = NULL;

username = reader1.getstring (0);
textarray1 = reader1.getstring (1 ). split (New char [] {':'});
text1 = reader1.getstring (2);
int num1 = (INT) reader1.getbytes (3, (long) 0, null, 0, 0);
buffer1 = new byte [num1];
reader1.getbytes (3, (long) 0, buffer1, 0, num1 );

Profilebase profile = (profilebase) type. getconstructor (New Type [0]). Invoke (new object [0]);

Profile. initialize (username, true );

Parsedatafromdb (textarray1, text1, buffer1, profile. propertyvalues );

List. Add (profile );

}

Return list;
}

Static void parsedatafromdb (string [] names, string values, byte [] Buf, settingspropertyvaluecollection properties)
{
If (names! = NULL) & (values! = NULL) & (BUF! = NULL) & (properties! = NULL )))
{
Try
{
For (INT num1 = 0; num1 <(names. Length/4); num1 ++)
{
String text1 = Names [num1 * 4];
Settingspropertyvalue value1 = properties [text1];
If (value1! = NULL)
{
Int num2 = int. parse (Names [(num1 * 4) + 2], cultureinfo. invariantculture );
Int num3 = int. parse (Names [(num1 * 4) + 3], cultureinfo. invariantculture );
If (num3 =-1 )&&! Value1.property. propertytype. isvaluetype)
{
Value1.propertyvalue = NULL;
Value1.isdirty = false;
Value1.deserialized = true;
}
If (Names [(num1 * 4) + 1] = "S") & (num2> = 0) & (num3> 0) & (values. length> = (num2 + num3 ))))
{
Value1.serializedvalue = values. substring (num2, num3 );
}
If (Names [(num1 * 4) + 1] = "B") & (num2> = 0) & (num3> 0) & (BUF. length> = (num2 + num3 ))))
{
Byte [] buffer1 = new byte [num3];
Buffer. blockcopy (BUF, num2, buffer1, 0, num3 );
Value1.serializedvalue = buffer1;
}
}
}
}
Catch
{
}
}
}

}

 

4. Use this class to return list <profilebase>

The horse has it.

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.