我已经用尽了一些东西,所以我希望有人可以帮我解决这个问题。
我正在创建一个“注册”页面。当用户单击“注册”按钮时,他们的信息(电子邮件,用户名,密码)需要存储在Access数据库中。
我已经创建了一个Web引用(http://localhost:36938/usconWebServices/membershipService.asmx)并试图在register.aspx.cs中调用“CreateUser”函数,但似乎无法正确使用它。
这是我对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");
}
}
}
以“if ...”开头的第3行给出了一个错误:“没有结束方法'CreateUser'需要3个争论。”我已经尝试取出参数以及整行,但仍然无效。
这就是我对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;
}
对此有任何帮助或建议将不胜感激!
答案 0 :(得分:1)
CreateUser()函数需要四个参数(用户newUser,字符串emailAddress,字符串用户名,字符串userPassword)。但是当你调用那个方法时,你只传递了三个参数。
更改
if (ws.CreateUser(txtEmailReg.Text, txtUsernameReg, txtPasswordReg))
传递所有四个参数。
user newUser=new Users();
if (ws.CreateUser(newUser,txtEmailReg.Text, txtUsernameReg.Text, txtPasswordReg.Text))
显然你缺少第一个参数,即用户类的对象。
或更改您的功能定义
public string CreateUser(user newUser, string emailAddress, string username, string userPassword)
到
public string CreateUser(string emailAddress, string username, string userPassword)
只接受三个参数