0
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");
我想存儲過程的參數和有這個存儲過程執行並獲得這個結果到一個數據集,但我什麼也沒有得到..字面意思。沒有例外,只是沒有存儲過程的結果。爲什麼執行時返回沒有結果?
這是存儲過程:
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
檢查從內部到外部的對象。你正在打電話給USP,但是它能工作嗎?如果使用的謂詞沒有匹配,則不會得到任何結果,也不會發布錯誤。它只是沒有匹配的行。 –
您可以查看從sql profiller發送的sql語句以瞭解哪些參數值,您可能會發現錯誤在哪裏。參數值基於if。嘗試在dp2.fill後寫入參數值 –