我想學習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()'函數的代碼。它似乎並不需要你期望的參數。 –