我有一个搜索分支的方法。参数是分支代码,它应该返回分支的详细信息
public bool SearchBranch()
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBReader"].ConnectionString))
{
using (SqlCommand com = new SqlCommand("Reader.usp_SearchBranch", con))
{
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add("@BranchCode", SqlDbType.Int).Value = this.BranchCode;
con.Open();
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
this.BranchName = dr.GetValue(0).ToString();
this.AreaCode = dr.GetValue(1).ToString();
this.RegionCode = dr.GetValue(2).ToString();
this.CompanyCode = dr.GetValue(3).ToString();
this.CompanyName = dr.GetValue(4).ToString();
return true;
}
else
{
return false;
}
}
}
}
这是我在 Web 服务中的 Web 方法中的代码(我不知道这是否正确)
[WebMethod(Description = "Search Affected User from Database in Access Request")]
public bool SearchBranchAccessRequest(AccessRequest accessrequest)
{
return accessrequest.SearchBranch();
}
这就是我在我的网页中访问/调用 web 方法的方式
protected void SearchBranchButton_Click(object sender, EventArgs e)
{
try
{
accessrequest.BranchCode = Convert.ToInt32(BranchCodeTextBox.Text);
iTicketWebService.SearchBranchAccessRequest(accessrequest);
if (iTicketWebService.SearchBranchAccessRequest(accessrequest) == true)
{
BranchNameLabel.Text = accessrequest.BranchName;
AreaLabel.Text = accessrequest.AreaCode;
RegionLabel.Text = accessrequest.RegionCode;
CompanyCodeLabel.Text = accessrequest.CompanyCode;
CompanyLabel.Text = accessrequest.CompanyName;
BranchEmailLabel.Text = accessrequest.BranchCode + "@pjlhuillier.com";
}
else
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", "<script type=\"text/javascript\">alert('Record not found. Please try again');</script>");
}
}
catch (Exception)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientScript", "<script type=\"text/javascript\">alert('Wrong Input. Please try again');</script>");
}
}
帮助!它不返回分行名称、区号、地区代码、公司代码和公司名称?