Solved

ASP.Net Membership table

Posted on 2011-03-10
4
430 Views
Last Modified: 2012-05-11
I'm trying to do a bulk insert of data into the aspnet_Membership table. I ahve existing records from a previous version of the syatem. I have already successfully insert the records into the aspnet_Users table. The Membership table holds the password and password hash, so I am trying to take advantage of the membership code. The membership class has a CreateUser method, so I would like to use that to iterate over every record in my orginal data table and then insert it into the membership table. I've been researing and asking questios, but I am still missing something. Any ideas are appreciated. My code so far (in C# and ASP.Net):

using System.Web.Security;
using System.Data;
using System.Data.SqlClient;

protected void Import_Click(object sender, EventArgs e)

string connString = "data source=(local);Inital Catalog="Testing";Integrated Security=true;);
SqlConnection conn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand("Select UserName, Password, Email from View3", conn);
conn.Open();
DataTable tbl = new DataTable();

foreach (DataRow row in tbl.Rows)
{
System.Web.Security.MembershipCreateStatus status;
Membership.CreateUser(tbl["UserName"], tbl["Password"], tbl["Email"], "Test", "Test", true, status);
}
conn.Close();
0
Comment
Question by:dodgerfan
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
daveamour earned 500 total points
ID: 35106951
You need to populate your Datatable  - do this with and adapter and use th fill method

http://msdn.microsoft.com/en-us/library/bh8kx08z(v=vs.71).aspx
0
 

Author Comment

by:dodgerfan
ID: 35111354
I'm a little lost with this. Is there an example of inserting data from one data table to a table in SQL server out there?
0
 

Author Comment

by:dodgerfan
ID: 35112532
My code now looks like this:
protected void Import_Click(object sender, EventArgs e)

string strConn = "data source=(local);Inital Catalog="Testing";Integrated Security=true;);
string strSQL = "Select * from view3";
string password = "Password";

Sql Connection my Connection = new SQLConnection(strConn);

myConnection.Open();
SqlDataAdapter da = new SqlDataAdapter(strSQL, myConnection);
DataTable dt = new DataTable();
da.Fill(dt);

foreach (DataRow row in dt.Rows)
{
      MembershipUser newUser = Membership.CreateUser("username", password, "email");
}

Just running the line:  MembershipUser newUser = Membership.CreateUser("username", password, "email"); works in and of itself. What I want to do is run that line for each row in my datatable. The datatable data has two fields for each user, username and email. I'm setting the same password for everyone initially. What is the syntax for using the columns for each row in the datatable instead of the variables in there now?
0
 
LVL 19

Expert Comment

by:daveamour
ID: 35114706
Sorry for the late reply but see you must have it sorted already.

To be honest though this sort of thing can be done from SQL server management studio with straight sql commands - much quicker and easier that way.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
which object should i use (efficiency) 5 45
asp.net mvc return json 2 53
asp.net mvc input file 2 32
Code works but it's slow 23 26
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now