我有一个网络方法函数检查数据库中是否存在名称,但我收到错误:
Error 114 'lookups_Creditor.CheckIfNameExists(string)': not all code paths return a value
这是网络方法:
[WebMethod]
public static bool CheckIfNameExists(string Name)//error on this line
{
try
{
Creditor.CheckIfNameCreditorExists(Company.Current.CompanyID, Name);
}
catch (Exception ex)
{
}
}
这是sql的搜索功能:
public static string CheckIfNameCreditorExists(int CompanyID, string Name)
{
DataSet ds = new DataSet();
string accNo = "";
string sql = "proc_CheckIfACCreditorExists";
string query = "SELECT c.* " +
" FROM Creditor c " +
" WHERE c.Company_ID = " + CompanyID + " AND c.Name LIKE '" + Name + "' ";
DataTable dt = new DataTable();
using (MySql.Data.MySqlClient.MySqlDataAdapter adapter = new MySql.Data.MySqlClient.MySqlDataAdapter(query, DataUtils.ConnectionStrings["TAT"]))
{
adapter.SelectCommand.CommandType = CommandType.Text;
adapter.SelectCommand.CommandText = query;
adapter.Fill(dt);
if (dt.Rows.Count > 0)
{
accNo = Convert.ToString(dt.Rows[0]["AccoutCode"]);
}
}
return accNo;
}
我正在尝试创建一种在数据库中搜索名称的方法。如果该名称存在,则返回与该名称关联的帐户代码。我将在屏幕上显示一条消息,告诉用户该名称已存在于帐户 ABC 中。
最佳答案
[WebMethod]
public static bool CheckIfNameExists(string Name)//error on this line
{
bool Result = false;
try
{
Result = Creditor.CheckIfNameCreditorExists(Company.Current.CompanyID, Name) != "";
}
catch (Exception ex)
{
}
return Result
}
关于c# - 并非所有代码路径都会在 Web 方法上返回值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32247633/