asp.net - C# - Read from excel sheet and pass variables into function -


i'm looking ideas best way of constructing code read excel file , create user accounts.

i have code both read excel file , create accounts, i'm unsure best way of passing data excel sheet "createuser" function.

any appreciated.

cheers.

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 * [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;             }          }     } } 

here's real simple:

while(dr.read()) {     string user = dr[0].tostring();     string pass = dr[1].tostring();     if(!string.isnullorwhitespace(user) && !string.isnullorwhitespace(pass))         createuser(user, pass) } dr.close() 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -