2

I've ran out of things to try, so I hope someone can help me with this.

I'm creating a "Register" page. When a user clicks the "Register" button, their information (email, username, password) needs to be stored into an Access database.

I've created a web reference ( http://localhost:36938/usconWebServices/membershipService.asmx ) and trying to call the "CreateUser" function in the register.aspx.cs, but can't seem to get it right.

Here's what I have for register.aspx.cs:

protected void btnRegister_Click(object sender, EventArgs e)
{
    wrefMembership.membershipService ws = new wrefMembership.membershipService();

    if (ws.CreateUser(txtEmailReg.Text, txtUsernameReg, txtPasswordReg))
    {

        try
        {
            Response.Redirect("mainContent.aspx");
        }
        catch (Exception er)
        {
            Response.Write("<b>Something really bad happened... Please try again.</b>");
        }
        finally
        {
            Response.Redirect("~/membersOnly/mainContent.aspx");
        }
    }
}

The 3rd line starting with "if..." is giving me an error: "No over for method 'CreateUser' takes 3 arguements." I've tried taking out the parameters as well as the entire line, but still didn't work.

And here's what I have for membershipService.cs:

[WebMethod(Description = "Create a new user, pass on a user object, returns a result string with information about processing result")]
public string CreateUser(user newUser, string emailAddress, string username, string userPassword)
{
    string query = "";
    DataSet ds = new DataSet();
    DataRow dr;
    int count;
    string result = "";

    try
    {
        //define query
        query = "SELECT * FROM UserInfo WHERE emailAddress='" + newUser.emailAddress + "'";
        ds = DataAccessService.RunSimpleQuery(query);

        if (ds.Tables[0].Rows.Count <= 0)
        {
            dr = ds.Tables[0].NewRow();
            dr["emailAddress"] = newUser.emailAddress;
            dr["username"] = newUser.username;
            dr["userPassword"] = userPassword;
            dr["registerDate"] = DateTime.Now;
            ds.Tables[0].Rows.Add(dr);
            result = DataAccessService.RunInsertCommand(query, ds);

            try
            {
                ds = DataAccessService.RunSimpleQuery(query);
                count = ds.Tables[0].Rows.Count; //last row is the new row!
                if (count > 0)
                {
                    dr = ds.Tables[0].Rows[count - 1];
                    result = "[000] OK: userID=" + dr["userID"].ToString();
                }
                else
                {
                    result = "[004] ERROR: User ID not found"; //user ID not found
                }
            }
            catch (Exception ex)
            {
                result = "ERROR: Could not update database: " + ex.Message + " *** ";
            }
        }
        else
        {
            result = "[003] ERROR: This e-mail account has already been registered with us."; //e-mail account already exists
        }
    }
    catch (Exception ex)
    {
        result = "[002] ERROR: " + query + Environment.NewLine + ex.Message + ex.StackTrace; //error
    }

    return result;
}

Any help or advice on this will be greatly appreciated!

jannn
  • 93
  • 1
  • 3
  • 10

1 Answers1

1

The CreateUser() function expects four parameters (user newUser, string emailAddress, string username, string userPassword). But when you are calling that method, you are passing only three parameters.

Change

if (ws.CreateUser(txtEmailReg.Text, txtUsernameReg, txtPasswordReg))

to pass all the four parameters.

user newUser=new Users();
if (ws.CreateUser(newUser,txtEmailReg.Text, txtUsernameReg.Text, txtPasswordReg.Text))

Obviously you are missing the first parameter, the object of user class.

Or change your function definition

public string CreateUser(user newUser, string emailAddress, string username, string userPassword)

to

public string CreateUser(string emailAddress, string username, string userPassword)

which accepts only three parameters

giftcv
  • 1,670
  • 15
  • 23
  • Thank you for your suggestions, giftcv. I added the "user" class to create 4 parameters and it gave me a red line underneath the word. So I hover over it and it suggested that I add "using wrefMembership;" which I did. Then the entire line became an error. When I hover over the word "user" again, it says: "Error: 'wrefMembership.user' is a 'type' but is used like a 'variable'." How do I do that? (sorry, I'm really new to this...) Thank you again. – jannn Nov 27 '11 at 05:21
  • Thank you for your guidance, giftcv! It still gave me an error, so I decided to try it inside the try-catch instead: user newUser = new user(); try { ws.CreateUser(newUser, txtEmailReg.Text, txtUsernameReg.Text, txtPasswordReg.Text); – jannn Nov 28 '11 at 05:56
  • haha there are no more errors in that part. The new user's info is stored in the database after also I fixed something else. Thanks again for your help! – jannn Nov 28 '11 at 06:18