Note that there are some explanatory texts on larger screens.

plurals
  1. POC# - Read from excel sheet and pass variables into function
    text
    copied!<p>I'm basically looking for some ideas as to the best way of constructing code to read an excel file and create user accounts.</p> <p>I already have the code to both read the excel file and create the accounts, however I'm unsure as to the best way of passing the data from the excel sheet into the "CreateUser" function.</p> <p>Any help is appreciated.</p> <p>Cheers.</p> <pre><code>using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; using System.Data.SqlClient; using System.IO; namespace INB201_SAMS.Admin { public partial class UploadList : System.Web.UI.Page { protected void UploadButton_Click(object sender, EventArgs e) { var upload = Path.Combine(Server.MapPath("~/upload"), "myfilename.xlsx"); CSVUpload.SaveAs(upload); var excelConString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0", upload); using (OleDbConnection con = new OleDbConnection(excelConString)) { con.Open(); OleDbCommand com = new OleDbCommand("Select * from [UserUpload$]", con); OleDbDataReader dr = com.ExecuteReader(); } File.Delete(upload); Response.Write("Upload Successfull!"); } protected bool CreateUser(string UsersUsername, string UsersPassword) { try { MembershipUser newUser = System.Web.Security.Membership.CreateUser(UsersUsername, UsersPassword); Roles.AddUserToRole(UsersUsername, "student"); return true; } catch (Exception ex) { MessageYo.Text = ex.ToString(); return false; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload