I am am trying to pass a parameter into my textbox which communicates to my database and runs a stored procedure on a button click.
I have the button working if I hard code a parameter value but I need to to accept parameters in a textbox.
Any ideas how I can fix this code to accomplish this?
This is one of my classes
public FixPayrollMonth PayrollMonth()
{
return StoreProcPayrollMonth("fix_Payroll_PayingMonth");
}
private FixPayrollMonth StoreProcPayrollMonth(string storeprocedurename)
{
FixPayrollMonth result = new FixPayrollMonth() {IsSuccess = false };
SqlCommand cmd = new SqlCommand(storeprocedurename, Connection);
cmd.Parameters.Add(new SqlParameter("@Month_Change", 123456 ));
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection.Open();
using (var data = cmd.ExecuteReader())
{
while (data.Read())
{
result.MonthChanged = Convert.ToInt32(data["MonthChanged"]);
result.IsSuccess = Convert.ToBoolean(data["IsSuccess"]);
}
}
return result;
}
This is my button click…I need to link it to my textbox called txtPay
protected void btnFixMnth_Click(object sender, EventArgs e)
{
var result = repo.PayrollMonth();
if (result.IsSuccess)
{
lblMessageBoxMnthChg.Text = "Succesful Month has been changed to: " + result.MonthChanged;
}
else
{
lblMessageBoxMnthChg.Text = "Failed to change month";
}
}
Your call to repo.PayrollMonth would required a parameter to pass in the value of the textbox. So in your button click event you would do:
And you repo would need to be modified to look like the following: