[英]Why Is this returning no results when executed?
SqlConnection conn = getConnection();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SP_PSLA_SEARCH"; //The stored procedure gets added
cmd.CommandTimeout = 0;
cmd.Connection = conn;
// Start adding the parameters of the stored procedure
cmd.Parameters.AddWithValue("@usrnm", thisUser.Username);
int constit = 0;
if (thisUser.Constituencies.Count > 0)
{
foreach (KeyValuePair<int, string> kp in thisUser.Constituencies)
{
if (kp.Value == ddlConstituency.SelectedValue.ToString())
{
constit = kp.Key;
break;
}
}
}
cmd.Parameters.AddWithValue("@cnstncy", constit);
string pdval = null;
int valtype = 0;
if (rbsearchradios.SelectedIndex == 0)
{
try
{
pdval = searchVal;
cmd.Parameters.AddWithValue("@Search", DBNull.Value);
cmd.Parameters.AddWithValue("@pd", int.Parse(pdval));
cmd.Parameters.AddWithValue("@type", valtype);
}
catch
{
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "stop", "alert('Invalid PD Number Supplied! Please Provide A Valid Submission.');", true);
return;
}
}
else
{
valtype = 1;
cmd.Parameters.AddWithValue("@Search", searchVal);
cmd.Parameters.AddWithValue("@pd", DBNull.Value);
cmd.Parameters.AddWithValue("@type", valtype);
}
cmd.Parameters.AddWithValue("@app", 1);
conn.Open();
// Creates Dataadapter for execution
SqlDataAdapter dp2 = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
dp2.Fill(ds, "name");
I am trying to the arguments of the stored procedure and the having this stored procedure execute and get this results into a dataset but I get nothing.. Literally. 我正在尝试存储过程的参数,并使该存储过程执行并将结果存储到数据集中,但是我什么也没得到。 There are no exceptions, just no result from the stored procedure. 没有例外,只是存储过程没有结果。
This is the stored procedure: 这是存储过程:
DECLARE @return_value int
EXEC @return_value = [dbo].[SP_PSLA_SEARCH]
@usrnm = N'tstone',
@cnstncy = 55,
@Search = N'primary',
@pd = NULL,
@type = 1,
@app = 1
SELECT 'Return Value' = @return_value
GO
To troubleshoot: 解决方法:
In general, you can also try to simplify and make your code more clear: 通常,您还可以尝试简化代码并使代码更清晰:
if (rbsearchradios.SelectedIndex == 0)
can be moved at the beginning, it makes no sense to create SqlCommand and then break 具有return且if (rbsearchradios.SelectedIndex == 0)
可以在开始时移动的块,因此创建SqlCommand然后中断就没有意义了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.