Web サービス、Linq、およびストアド プロシージャを通過する単純な [ユーザーの追加] ページを作成しようとしています。ストアド プロシージャの結果をブール値として返すように設定しました。問題は、常に偽として戻ってくることです。また、「エラー」メッセージが返されないため、エラーがどこにあるのかわかりません。
メインの .aspx ページはデータを通過して Web サービスに到達しているように見えるので、問題はないと思います。したがって、残りのコードのみを投稿します。
WebService.cs:
public bool AddUser(string Name, int Contact, string Email, string Password, bool Admin, string ImageURL)
{
bool result = false;
using (DataClassesDataContext dbcontext = new DataClassesDataContext())
{
var query = dbcontext.CreateUser(Name, Contact, Email, Password, Admin, ImageURL); //as far as I can see, the values get passed through these parameters. But the query returns false.
result = Convert.ToBoolean(query);
}
return result;
}
DataContext.designer.cs:
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.CreateUser")]
public int CreateUser([global::System.Data.Linq.Mapping.ParameterAttribute(Name="Name", DbType="VarChar(50)")] string name, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="ContactNo", DbType="Int")] System.Nullable<int> contactNo, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Email", DbType="VarChar(50)")] string email, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Password", DbType="VarChar(50)")] string password, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="Admin", DbType="Bit")] System.Nullable<bool> admin, [global::System.Data.Linq.Mapping.ParameterAttribute(Name="ImageURL", DbType="NVarChar(200)")] string imageURL)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), name, contactNo, email, password, admin, imageURL);
return ((int)(result.ReturnValue));
}
ストアド プロシージャ CreateUser:
ALTER PROCEDURE dbo.CreateUser
@Name varchar(50),
@ContactNo int,
@Email varchar(50),
@Password varchar(50),
@Admin bit,
@ImageURL nvarchar(200)
AS
INSERT INTO Users
([Name], ContactNo, Email, Password, Admin, ImageURL)
VALUES
(@Name, @ContactNo, @Email, @Password, @Admin, @ImageURL)