I did this using a SQL query to get the values to insert instead of using Excel, but I think it shows what you need. I had to add the MultipleActiverResultSets=true to the connection string to make it work, but it did.
SqlConnection conn;
SqlCommand comm;
SqlDataReader sdr;
string connstring = "Data Source=YourServer\\SQLEXPRESS;Initial Catalog=YourDatabase;Integrated Security=False;MultipleActiveResultSets=true;User Id=YourUsername;Password=YourPassword;Connect Timeout=0";
public void populateUsers()
{
try
{
conn = new SqlConnection(connstring);
conn.Open();
string query = "SELECT SSN, Password, LastName FROM Person";
comm = new SqlCommand(query, conn);
sdr = comm.ExecuteReader();
while(sdr.Read())
{
string sql = "INSERT into Users VALUES (@un, @pw, @fn)";
comm = new SqlCommand(sql, conn);
SqlParameter uname = new SqlParameter("@un", SqlDbType.Text);
uname.Direction = ParameterDirection.Input;
SqlParameter pword = new SqlParameter("@pw", SqlDbType.Text);
pword.Direction = ParameterDirection.Input;
SqlParameter fname = new SqlParameter("@fn", SqlDbType.Text);
fname.Direction = ParameterDirection.Input;
comm.Parameters.Add(uname);
comm.Parameters.Add(pword);
comm.Parameters.Add(fname);
uname.Value = sdr["SSN"].ToString();
pword.Value = sdr["Password"].ToString();
fname.Value = sdr["LastName"].ToString();
comm.ExecuteNonQuery();
}
}
catch(Exception exc)
{
}
finally
{
sdr.Dispose();
comm.Dispose();
conn.Close();
}
Hope it helps.
-strimpf