+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: import excel file into asp_net membership

  1. #1
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    215
    Rep Power
    4

    import excel file into asp_net membership

    Good morning everyone it's peeb, hope everyone is well. I"m currently working on a login for a client. They initially will have about 1,000 users that will need to be created to login into the asp.net (sql) system.

    Instead of the system admin sitting and creating all 1,000 users, we thought of using an excel file and importing the users into the system.

    Now I have never coded something like that, but i'm researching things online and there are a few good articles.

    My question is can you import excel file into the asp_net membership tables, because the passwords are encrypted, etc. So my thoughts are you may not be able to import into those tables unless you build a customized login?

    Can this be done? If so does anyone have any good articles that will help in coding to import excel file into sql, again i've never coded something like that?

    As alway everyone, I appreciate any and all help.

    thanks.

  2. #2
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    My initial guess is that you will not be able to import directly into the tables from Excel, as you pointed out the passwords are encrypted, and you have things like application id to worry about. Rather, it should be possible to create an application (even a console app, tho I'm think at about 100,000 feet at the moment) that could take you Excel SS (with Passwords in plain text? Oh the Horror) and using the Membership class methods to create the entries in the the DB. (Consider exporting the SS as a flat file -- just way easier).

    Just another half baked idea -- look at the stored procs used by the membership db (if any) and see if you can use them along with the flat file idea.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  3. #3
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Just took a look at the sprocs for membership. Looks like you could use them for what you are trying to do.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  4. #4
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Don't know if this will help, but you could try opening the Excel File using an OLE DB connection and then iterate through the records to add each of them individually.

    Code:
    imports System.Data
    .
    .
    .
    .
    .
    .
    Dim excelconnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=full_path_to_filename\excelfile.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1;"""
    Dim excelconn As New OleDb.OleDbConnection(excelconnString)
    Dim excelcom As New OleDb.OleDbCommand("SELECT * FROM [Sheet1$]", excelconn)
    Dim exceldtr As OleDB.OleDbDataReader
     
    excelconn.Open
    exceldtr = excelcom.ExecuteReader()
    do while exceldtr.Read()
     
    'save into membership table
     
    loop
    exceldtr.close
    
    If you use a header row at the top of your excel SS you can then reference them using exceldtr("column_header") to retrieve the values.

    Maybe I've misunderstood what you're trying to do, but hope that helps.
    Last edited by richyrich; August 11th, 2008 at 12:07 PM. Reason: There's No New Instance of OleDbDataReader

  5. #5
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    215
    Rep Power
    4

    reply

    Hey thanks wolffy, I thought you couldn't import into the asp.net membership tables, but I wasn't for sure.

    Sorry dude, i'm a little confused on your idea. Now you're saying I should look at the membeship Stored proc's and have it import the excel data as entries into the database. Create and application that does this, right?



    Quote Originally Posted by Wolffy View Post
    My initial guess is that you will not be able to import directly into the tables from Excel, as you pointed out the passwords are encrypted, and you have things like application id to worry about. Rather, it should be possible to create an application (even a console app, tho I'm think at about 100,000 feet at the moment) that could take you Excel SS (with Passwords in plain text? Oh the Horror) and using the Membership class methods to create the entries in the the DB. (Consider exporting the SS as a flat file -- just way easier).

    Just another half baked idea -- look at the stored procs used by the membership db (if any) and see if you can use them along with the flat file idea.

  6. #6
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Take a look back at RR post right before yours. If you combine his idea with mine, you should have a workable(?) solution. Where he has the comment 'save into membership table is where you would call the necessary sprocs to actually do the inserts.

    And thanks to RR -- I needed something like that just today to import Excel data into a database.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  7. #7
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    215
    Rep Power
    4

    reply

    Okay thanks to you both Rich and Wolf, I'll try that.

    I'll let you know how it turns out.

    Keep an eye out for me, because I know I will post again on this.

    Thanks.

    Quote Originally Posted by Wolffy View Post
    Take a look back at RR post right before yours. If you combine his idea with mine, you should have a workable(?) solution. Where he has the comment 'save into membership table is where you would call the necessary sprocs to actually do the inserts.

    And thanks to RR -- I needed something like that just today to import Excel data into a database.

  8. #8
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    215
    Rep Power
    4

    reply, help

    Okay everyone, this is what I got and I Knew this would be a little bit of a problem. I'm using the aspnet_membership_creatUser stored procedure to create a new user from an excel file.

    The excel file upload works and it reads the excel file (THANKS TO RR & wolffy) but i'm having problem insert it into the DB.

    I get and error:
    Procedure 'aspnet_Membership_CreateUser' expects parameter '@PasswordSalt', which was not supplied.Problem
    In the procedure is does ask for @PasswordSalt, but I have no idea what it is.

    In the table the @PasswardSalt is encrypted.

    Any ideas on what values do I need to insert into the table?


    Code:
    Imports System.Data.SqlClient
    Imports System.Web.Configuration
    Imports System.IO
    Imports System.Text
    Imports System.Web.mail
    Imports System.IO.stream
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Net.Mail
    Imports System.Text.regularexpressions
    Imports System
    Imports System.Web.Security
    Imports System.Web.UI
    Imports System.Web.UI.UserControl
    Imports System.Web.UI.WebControls
    Imports System.Web.Management
    Imports System.Diagnostics.Process
    Partial Class exceluserimport
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim doctxt As String = Right(FileUpload1.FileName, 3).ToString 'upload text file in upper and lower case "txt"
            Dim fileName As String = Server.MapPath("uploads/testexcelmembership.xls")
            If doctxt.ToLower = "xls" Or doctxt.ToLower = Nothing Or doctxt = "" Then
                If FileUpload1.HasFile And doctxt.ToLower = "xls" Then
                    Try
                        File.Delete(Server.MapPath("uploads/testexcelmembership.xls"))
                        FileUpload1.SaveAs(Server.MapPath("uploads\" & ID + FileUpload1.FileName))
                    Catch ex As Exception
                        Response.Write("file not uploaded" & ex.Message)
                    End Try
                End If
            Else
                Label2.Visible = True
            End If
    
            Dim app As String = ""
            Dim pass As String = ""
            Dim email As String = ""
            Dim lowemail As String = ""
            Dim passwardformat As String = ""
            Dim isappr As String = ""
            Dim islock As String = ""
            Dim username As String = ""
    
    
    
    
            Dim excelConn As String = "Provider=Microsoft.Jet.OleDb.4.0;" _
                                & "data source=C:\Documents and Settings\peebman2000\My Documents\Visual Studio 2005\WebSites\testhelp3\uploads\testexcelmembership.xls;" _
                                & "Extended Properties=Excel 8.0;"
            'First DataGrid
            Dim excel_obj As New OleDbConnection(excelConn)
            Dim excelcom As New OleDb.OleDbCommand("Select ApplicationId,Password,Email,LoweredEmail,PasswordFormat,IsApproved,IsLockedOut, UserName From [Sheet1$]", excel_obj)
            'Dim strExcel As String = "Select ApplicationId,Password,Email,LoweredEmail,PasswordFormat,IsApproved,IsLockedOut From [Sheet1$]"
            Dim excel_dtr As OleDb.OleDbDataReader
    
            excel_obj.Open()
            excel_dtr = excelcom.ExecuteReader()
            Do While excel_dtr.Read()
                app = excel_dtr("ApplicationID")
                pass = excel_dtr("Password")
                email = excel_dtr("Email")
                'lowemail = excel_dtr("LoweredEmail")
                passwardformat = excel_dtr("PasswordFormat")
                isappr = excel_dtr("IsApproved")
                islock = excel_dtr("IsLockedOut")
                username = excel_dtr("UserName")
    
    
    
                Dim dataadapter As SqlDataAdapter
                Dim datacommand As SqlCommand
    
                dataadapter = New SqlDataAdapter
                datacommand = New SqlCommand
    
                datacommand.CommandText = ("aspnet_Membership_CreateUser")
                datacommand.Connection = New SqlConnection(ConfigurationManager.ConnectionStrings("dave").ToString)
    
                dataadapter = New SqlDataAdapter("aspnet_Membership_CreateUser", datacommand.Connection)
    
                datacommand.CommandType = Data.CommandType.StoredProcedure
    
                datacommand.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = app
    
                datacommand.Parameters.Add("@Password", SqlDbType.NVarChar, 128).Value = pass
    
                datacommand.Parameters.Add("@Email", SqlDbType.NVarChar, 256).Value = email
    
                'datacommand.Parameters.Add("@LoweredEmail", SqlDbType.NVarChar, 256).Value = lowemail
    
                datacommand.Parameters.Add("@PasswordFormat", SqlDbType.Int).Value = CType(passwardformat, Int32)
    
                datacommand.Parameters.Add("@UserName", SqlDbType.NVarChar, 256).Value = username
    
              '
    
                datacommand.Connection.Open()
                Try
                    datacommand.ExecuteNonQuery()
                    Response.Write("inserted data")
                    Response.End()
                Catch ex As Exception
                    Response.Write(ex.Message.ToString() + "Problem")
                    Response.End()
                End Try
    
                datacommand.Connection.Close()
    
            Loop
    
            excel_dtr.Close()
            excel_obj.Close()
            'Try
            '    Response.Write(app & pass & email & lowemail & passwardformat & isappr & islock)
            '    Response.End()
    
            'Catch ex As Exception
            '    Response.Write(ex.Message.ToString() + "error with code")
            '    Response.End()
            'End Try
    
    
    
    
            'lblSql1.Text = strExcel
            'Dim objCmd As New OleDbCommand(strExcel, excel_obj)
            'Try
            '    excel_obj.Open()
            '    GridView1.DataSource = objCmd.ExecuteReader()
            '    GridView1.DataBind()
            'Catch exc As Exception
            '    Response.Write(exc.ToString())
            'Finally
            '    excel_obj.Dispose()
            'End Try
    
        End Sub
    End Class
    

  9. #9
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    Yeah, I thought that trying to use the sprocs directly would be kind of a hack. Now that I see you code and have a second think, it would actually be easier to use the Membership.CreateUser method and avoid a lot of this BullFeathers. I bet you have all the info you need now from reading the Excel SS to just call one the CreateUser methods.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  10. #10
    Barn Enthusiast peebman2000 is on a distinguished road peebman2000's Avatar
    Join Date
    Mar 2008
    Posts
    215
    Rep Power
    4

    reply

    Thanks wolffy, that worked, I like that. I may have some questions about creating a new user with roles. I'm practicing with that now, so you may or may not hear from me again on this topic.

    But again I appreciate your help dude, take care.


    Code:
      Dim newUser As MembershipUser = Membership.CreateUser(username, pass, email)
                'newUser.Comment = comment.Text
                Membership.UpdateUser(newUser)
    

    Quote Originally Posted by Wolffy View Post
    Yeah, I thought that trying to use the sprocs directly would be kind of a hack. Now that I see you code and have a second think, it would actually be easier to use the Membership.CreateUser method and avoid a lot of this BullFeathers. I bet you have all the info you need now from reading the Excel SS to just call one the CreateUser methods.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Break & Continue in VB (Excel)
    By Lauramc in forum Microsoft Office
    Replies: 5
    Last Post: July 24th, 2008, 06:59 PM
  2. From excel to database/web app
    By Rebelle in forum Database Design Help
    Replies: 7
    Last Post: July 10th, 2008, 02:36 PM
  3. Excel question
    By Rebelle in forum Microsoft Office
    Replies: 11
    Last Post: May 27th, 2008, 08:22 PM
  4. Retrieving Web Data using Excel
    By mehere in forum Microsoft Office
    Replies: 13
    Last Post: May 22nd, 2008, 04:14 PM
  5. opening excel file
    By todd2006 in forum ASP Development
    Replies: 5
    Last Post: April 30th, 2008, 06:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO