在 C# 中将第二个参数传递给存储过程
Passing Second Parameter to Stored Procedure in C#
在下面的代码中,我试图检索经理的 ID,然后必须将其作为第二个参数传递给 SQL 存储过程,如下面的代码所示:
目前代码只使用一个参数(EmpID)。
void EmpProfileLists(string EmpId,string EmpName)
{
if (EmpId == "0")
{
Label2.Text = "There is no Emp associated with your account";
Label2.Visible = true;
}
else Label2.Visible = false;
try
{
Session["EmpId"] = EmpId;
Label1.Text = EmpId;
if (Session["MgrName"] != null) Session.Remove("MgrName");
var claimsIdentity = Context.Emp.Identity as ClaimsIdentity;
foreach (var claim in claimsIdentity.Claims)
{
{
Session.Add("MgrName", "micro\"+Session["MgrName"].Substring(Session["MgrName"].LastIndexOf("/")));
}
}
string MgrName = Session["MgrName"].ToString();
LoadProfiles(EmpId);
}
catch (Exception)
{
}
}
private void LoadProfiles(string EmpId)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Exec EmpReports " + EmpId);
DataTable dt = new DataTable();
da.Fill(dt);
RadGrid1.DataBind();
}
catch (Exception)
{
}
}
代码在通过时仅使用员工 ID 就可以正常工作,但我也在尝试添加经理 ID。
有人可以帮忙吗?
SqlCommand command = new SqlCommand("EmpReports", WebConfigurationManager.ConnectionStrings["EmpReportConnectionString"].ToString());
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@EmpId", SqlDbType.Int).Value = EmpId;
command.Parameters.Add("@ManId", SqlDbType.Int).Value = ManId;
command.ExecuteNonQuery();
在下面的代码中,我试图检索经理的 ID,然后必须将其作为第二个参数传递给 SQL 存储过程,如下面的代码所示:
目前代码只使用一个参数(EmpID)。
void EmpProfileLists(string EmpId,string EmpName)
{
if (EmpId == "0")
{
Label2.Text = "There is no Emp associated with your account";
Label2.Visible = true;
}
else Label2.Visible = false;
try
{
Session["EmpId"] = EmpId;
Label1.Text = EmpId;
if (Session["MgrName"] != null) Session.Remove("MgrName");
var claimsIdentity = Context.Emp.Identity as ClaimsIdentity;
foreach (var claim in claimsIdentity.Claims)
{
{
Session.Add("MgrName", "micro\"+Session["MgrName"].Substring(Session["MgrName"].LastIndexOf("/")));
}
}
string MgrName = Session["MgrName"].ToString();
LoadProfiles(EmpId);
}
catch (Exception)
{
}
}
private void LoadProfiles(string EmpId)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("Exec EmpReports " + EmpId);
DataTable dt = new DataTable();
da.Fill(dt);
RadGrid1.DataBind();
}
catch (Exception)
{
}
}
代码在通过时仅使用员工 ID 就可以正常工作,但我也在尝试添加经理 ID。
有人可以帮忙吗?
SqlCommand command = new SqlCommand("EmpReports", WebConfigurationManager.ConnectionStrings["EmpReportConnectionString"].ToString());
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@EmpId", SqlDbType.Int).Value = EmpId;
command.Parameters.Add("@ManId", SqlDbType.Int).Value = ManId;
command.ExecuteNonQuery();