dodgerfan
asked on
Insert into a SQL server table from a datatable
I'm trying to insert each row from a datatable into a sql server table. I can;t seem to get the syntax right in trying to get it to work. My code is below. I;m not sure how to tell it how to get the values from certain feilds in the datatable.
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?
My code now looks like this:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER