导入用户ASP.NET成员从一个文件 [英] import users to ASP.NET membership from a file
本文介绍了导入用户ASP.NET成员从一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用ASP.NET成员资格的网站。我也有大约60用户记录的Excel文件。如何导入记录到会员数据库,而不必全部60键入到ASP.NET网站管理工具。
感谢您
解决方案
的foreach(记录中记录){
如果(!(Roles.RoleExists(记录[角色])){
Roles.CreateRole(记录[角色]);
}如果(Membership.GetUser(记录[用户名])== NULL){
System.Web.Security.MembershipCreateStatus状态;
Membership.CreateUser(记录[用户名],记录[密码],记录[电子邮件],记录[RSecurityQuestion],记录[SecurityAnswer],真实,地位);
如果(状态== System.Web.Security.MembershipCreateStatus.Success){
Roles.AddUserToRole(记录[用户名],记录[角色]);
}
}
}
我不记得了code从Excel创建文件记录了我的头顶。
编辑: 这里是一个很好的张贴在如何读/写擅长使用ADO.NET文件
I have a site using ASP.NET membership. I also have an excel file with about 60 user records. How can I import the records into the membership database, without having to type all 60 into the ASP.NET Web Site Administration Tool.
Thank you
解决方案
foreach (record in recordset) {
if (!(Roles.RoleExists(record["Role"])) {
Roles.CreateRole(record["Role"]);
}
if (Membership.GetUser(record["Username"]) == null) {
System.Web.Security.MembershipCreateStatus status;
Membership.CreateUser(record["Username"], record["Password"], record["Email"], record["RSecurityQuestion"], record["SecurityAnswer"], true, status);
if (status == System.Web.Security.MembershipCreateStatus.Success) {
Roles.AddUserToRole(record["Username"], record["Role"]);
}
}
}
I can't recall the code to create a recordset from an Excel file off the top of my head.
EDIT: Here is a good post on how to read/write excel files with ADO.NET
这篇关于导入用户ASP.NET成员从一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文