Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 19th, 2007, 09:32 AM
Authorized User
Join Date: Apr 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Migrating users¡¦ data into aspnet.mdf


NewUsers is a table (in the ASPNET.mdf) has UserName, Password, Email 3 fields.

I¡¦d like to copy all the data in NewUsers to the following tables

It should be

1. NewUsers.UserName => aspnet_users.UserName
2. NewUsers.Password => aspnet_membership. Password
3. NewUsers.Email => aspnet_membership.Email
4. and setting the newsletter <SubscriptionType> to ¡§Html¡¨ in the aspnet_Profile table

How to do it? With store procedure or need C# /VB.net code?

  #2 (permalink)  
Old April 20th, 2007, 10:23 AM
Authorized User
Join Date: Apr 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

I did.
protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            SqlConnection MyConnection;
            SqlCommand MyCommand;
            SqlDataReader MyReader;

            string cnnString = "your ConnectionString";
            MyConnection = new SqlConnection();
            MyConnection.ConnectionString = cnnString;

            MyCommand = new SqlCommand();
            MyCommand.CommandText = "SELECT [UserName], [password], [email] FROM [NewUser]";
            MyCommand.CommandType = CommandType.Text;
            MyCommand.Connection = MyConnection;

            MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConne ction);

                string theUserName = MyReader["UserName"].ToString();
                string thePassword =MyReader["password"].ToString() ;
                string theEmail = MyReader["email"].ToString();
                System.Web.Security.Membership.CreateUser(theUserN ame,thePassword,theEmail);

                ProfileCommon profile = this.Profile;
                profile = this.Profile.GetProfile(theUserName);

                profile.Preferences.Newsletter = (SubscriptionType)Enum.Parse(typeof(SubscriptionTy pe),"Html");

            } ;

  #3 (permalink)  
Old April 21st, 2007, 10:18 AM
Friend of Wrox
Join Date: Jun 2003
Location: Atlanta, Georgia, USA.
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts

This is handy code for anyone who wants to preload users. The Membership class will encrypt the passwords for you if you do it this way. Creating the Profile and setting it to Html is a nice touch.

People often need to create canned accounts for QA testers, or training accounts for user training. Anytime you create these common accounts you have to either delete them afterward, or change the passwords on them.

By the way, since you took extra effort to dispose the command and connection, I thought I'd point out a common misunderstanding in the Reader. The CommandBehavior.CloseConnection will only execute if ALL the records are actually read. If an exception were to occur, the connection would stay open. This isn't a big deal on this "one time" code, but it's nice the remember the importance of try/finally whenever you use a Reader in production code.



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
User Accounts ASPNET.mdf pschulz ASP.NET 2.0 Basics 3 June 19th, 2008 12:41 PM
ASPNET account for ASPNET.MDF DB-Please help rsearing ASP.NET 2.0 Basics 13 November 6th, 2007 11:54 PM
Migrating Data Problem Charlie05 BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 March 28th, 2007 04:08 PM
localhost/aspnet access of the aspnetdb.mdf file rsearing ASP.NET 2.0 Basics 22 August 4th, 2006 02:28 PM
migrating data using FOR EACH? krstofer Classic ASP Databases 1 April 15th, 2004 03:48 PM

All times are GMT -4. The time now is 11:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.