Along with John's suggestion (which is quick and good), you can use a
ref
variable. The calling method will look like the following (please not the new
string
variable, and a new parameter is passed in the function call):
parameters = new string[] { "@TrxNum", "@ShortDesc", "@PaymentOption" };
vals = new string[] { lblTrxNum.Text, txtShortDesc.Text, drpPaymentOptions.SelectedValue };
string ExceptionMsg = "";
DataTable dt = reimburseClass.getDataTableParameter("[NewSP_InsertUpdateReimburseTrxHDR]", parameters, vals, ref ExceptionMsg);
if (!ExceptionMsg.Equals(""))
{
...........
...........
}
The method
getDataTableParameter
now looks like the following. See a new parameter is added at the end, and there is a change in the CATCH block.
public DataTable getDataTableParameter(string qry, string[] param, string[] values, ref string ExceptionMsg)
{
dt = new DataTable();
try
{
con.Open();
cmd = new SqlCommand(qry, con);
cmd.CommandType = CommandType.StoredProcedure;
for (int i = 0; i <= param.Length - 1; i++)
{
cmd.Parameters.AddWithValue(param[i], values[i]);
}
da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
catch (Exception ex)
{
ExceptionMsg = Ex.Message;
}
finally
{
con.Close();
}
return dt;
}