这是我的代码隐藏的片段:
SqlConnection connection2 = new SqlConnection(str2);
SqlCommand cmd2 = new SqlCommand();
cmd2.CommandType = CommandType.StoredProcedure;
cmd2.CommandText = "" + MyRptSproc + "";
cmd2.Connection = connection2;
//Set up the parameters, if they exist
if (MyUseDates != "N")
{
cmd2.Parameters.Add("@StDate", SqlDbType.Date).Value = DateTime.Parse(txtStDate.Value);
cmd2.Parameters.Add("@EnDate", SqlDbType.Date).Value = DateTime.Parse(txtEnDate.Value);
}
if (MyPlatform != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MyPlatform", cboPlatform.SelectedValue));
}
if (MyManager != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MyManager", cboManager.SelectedValue));
}
if (MyAuditManager != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MyAuditManager", cboAuditorManager.SelectedValue));
}
if (MySampleTitle != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MySampleTitle", cboSampleTitle.SelectedValue));
}
if (MyAuditType != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MyAuditType", cboAuditType.SelectedValue));
}
if (MyLocation != "N")
{
cmd2.Parameters.Add(new SqlParameter("@MyLocation", cboLocation.SelectedValue));
}
try
{
connection2.Open();
GridView_Reports.EmptyDataText = "No Records Found";
var adapter = new SqlDataAdapter(cmd2);
var ds = new DataSet();
adapter.Fill(ds, "MyTableName");
// Add this to a session variable so the datagrid won't get NULLed out on repost
Session["SSRptMenu"] = ds;
GridView_Reports.DataSource = ds;
GridView_Reports.DataBind();
所以我正在逐步完成这段代码,然后进入
var adapter = new SqlDataAdapter(cmd2);
我突出显示“cmd2”,它告诉我它正在查看什么服务器,命令文本是什么等等...它还告诉我,为这个特定情况选择了5个参数。
我的问题是;如何判断选择哪些参数以及它们的值是什么?我已经深入研究了几乎每个菜单项,似乎无法找到它。
答案 0 :(得分:0)
如果其他人需要此信息,我发现它在:
cmd2 -->
Parameters -->
base -->
base -->
Non-Public members -->
[System.Data.SqlClient.SqlParameterCollection] -->
_items -->
在那里你可以找到参数列表,然后在每个参数下你可以找到它的值。