我正在尝试学习C#并遇到了问题,但我不确定它是什么。我试图通过Web服务从实体框架工作调用存储过程。但是,我不断收到错误:
CS1501: No overload for method 'CreateUser' takes 1 arguments
我的sql数据表只是一个基本表(在其他情况下可以正常工作)。我已将存储过程(CreateUser)放入我的Entity数据模型中。然后我创建了一个没有返回值的Function(CreateUser)。
这是函数,在我试图传递的WebService.cs中,我找回了上面的错误:
public void AddUser(string Name, int Contact, string Email, string Password, bool Admin, string ImageURL)
{
UsersEntities entdb = new UsersEntities();
NewUser newuser = new NewUser {
Name = Name,
ContactNo = Contact,
Email = Email,
Password = Password,
Admin = Admin,
ImageURL = ImageURL};
entdb.CreateUser(newuser);
}
由于之前的错误,我还创建了一个类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class NewUser
{
public string Name { get; set; }
public int ContactNo { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public bool Admin { get; set; }
public string ImageURL { get; set; }
}
从正常页面调用Web服务(我只是尝试测试它,所以我没有输入任何其他值):
protected void AddBtn_Click(object sender, EventArgs e)
{
CustomWebService cws = new CustomWebService();
cws.AddUser("testName", 12345678, "testEmail", "testPassword", true, "testImage");
}
如果有人能提供帮助,我将不胜感激!
提前致谢!
已编辑:添加CreateUser功能:
#region Function Imports
/// <summary>
/// No Metadata Documentation available.
/// </summary>
/// <param name="name">No Metadata Documentation available.</param>
/// <param name="contactNo">No Metadata Documentation available.</param>
/// <param name="email">No Metadata Documentation available.</param>
/// <param name="password">No Metadata Documentation available.</param>
/// <param name="admin">No Metadata Documentation available.</param>
/// <param name="imageURL">No Metadata Documentation available.</param>
public int CreateUser(global::System.String name, Nullable<global::System.Int32> contactNo, global::System.String email, global::System.String password, Nullable<global::System.Boolean> admin, global::System.String imageURL)
{
ObjectParameter nameParameter;
if (name != null)
{
nameParameter = new ObjectParameter("Name", name);
}
else
{
nameParameter = new ObjectParameter("Name", typeof(global::System.String));
}
ObjectParameter contactNoParameter;
if (contactNo.HasValue)
{
contactNoParameter = new ObjectParameter("ContactNo", contactNo);
}
else
{
contactNoParameter = new ObjectParameter("ContactNo", typeof(global::System.Int32));
}
ObjectParameter emailParameter;
if (email != null)
{
emailParameter = new ObjectParameter("Email", email);
}
else
{
emailParameter = new ObjectParameter("Email", typeof(global::System.String));
}
ObjectParameter passwordParameter;
if (password != null)
{
passwordParameter = new ObjectParameter("Password", password);
}
else
{
passwordParameter = new ObjectParameter("Password", typeof(global::System.String));
}
ObjectParameter adminParameter;
if (admin.HasValue)
{
adminParameter = new ObjectParameter("Admin", admin);
}
else
{
adminParameter = new ObjectParameter("Admin", typeof(global::System.Boolean));
}
ObjectParameter imageURLParameter;
if (imageURL != null)
{
imageURLParameter = new ObjectParameter("ImageURL", imageURL);
}
else
{
imageURLParameter = new ObjectParameter("ImageURL", typeof(global::System.String));
}
return base.ExecuteFunction("CreateUser", nameParameter, contactNoParameter, emailParameter, passwordParameter, adminParameter, imageURLParameter);
}
答案 0 :(得分:0)
您的CreateUser方法需要6个参数(name,contactNo,email,password,admin,ImageUrl),但您传入的用户是一个参数。你需要这样做:
NewUser newuser = new NewUser {
Name = Name,
ContactNo = Contact,
Email = Email,
Password = Password,
Admin = Admin,
ImageURL = ImageURL};
entdb.CreateUser(newuser.Name, newuser.ContactNo, newuser.Email, newuser.Password, newuser.Admin, newuser.ImageURL);
或
修改方法以仅采用NewUser参数,并在方法体中使用属性。