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!