Insert into a SQL server table from a datatable
Posted on 2011-03-11
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";Integrated Security=true;);
string strSQL = "Select * from view3";
string password = "Password";
Sql Connection my Connection = new SQLConnection(strConn);
SqlDataAdapter da = new SqlDataAdapter(strSQL, myConnection);
DataTable dt = new DataTable();
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?