dodgerfan
asked on
ASP.Net Membership table
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";Integrat ed 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.Member shipCreate Status status;
Membership.CreateUser(tbl[ "UserName" ], tbl["Password"], tbl["Email"], "Test", "Test", true, status);
}
conn.Close();
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";Integrat
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.Member
Membership.CreateUser(tbl[
}
conn.Close();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My code now looks like this:
protected void Import_Click(object sender, EventArgs e)
string strConn = "data source=(local);Inital Catalog="Testing";Integrat ed 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("use rname", password, "email");
}
Just running the line: MembershipUser newUser = Membership.CreateUser("use rname", 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?
protected void Import_Click(object sender, EventArgs e)
string strConn = "data source=(local);Inital Catalog="Testing";Integrat
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("use
}
Just running the line: MembershipUser newUser = Membership.CreateUser("use
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.
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.
ASKER