我想学习C#并遇到问题,但我不确定它是什么。我正尝试通过Web服务从实体框架调用存储过程。然而,我不断收到一个错误:我的SQL数据表只是一个基本的表(在其他情况下工作正常)。我已经将存储过程(CreateUser)放入我的实体数据模型中。然后我创建了一个没有返回值的函数(CreateUser)。将类添加到只有1个参数的方法中?
这是函数,在我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);
}
显示'UserEntities'。 –
你能向我们展示'CreateUser'的方法签名吗? –
请向我们展示您的'UsersEntities.CreateUser()'函数的代码。它似乎并不需要你期望的参数。 –