我正在尝试学习 C# 并遇到了一个问题,但我不确定它是什么。我正在尝试通过 Web 服务从实体框架调用存储过程。但是,我不断收到一个错误:
CS1501: No overload for method 'CreateUser' takes 1 arguments
我的 sql 数据表只是一个基本表(在其他情况下可以正常工作)。我已将存储过程 (CreateUser) 放入我的实体数据模型中。然后我创建了一个没有返回值的函数 (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);
}