there's bits missing from that, make a global var private
SqlConnection con; to the class
private void Open()
{
con = new SqlConnection("server=" + server + ";database=" + db + ";User Id=" +
user + ";password=" + pass);
//..........different ways to do this ia web.config, global.asax etc
}
private SqlCommand CreateCommand(string procName, SqlParameter[] prams)
{
SqlCommand cmd = null;
// make sure connection is open
Open();
cmd = new SqlCommand(procName, con);
cmd.CommandType = CommandType.StoredProcedure;
// add proc parameters
if (prams != null)
{
foreach (SqlParameter parameter in prams)
cmd.Parameters.Add(parameter);
}
// return param
cmd.Parameters.Add(
new SqlParameter("ReturnValue", SqlDbType.Int, 4,
ParameterDirection.ReturnValue, false, 0, 0,
string.Empty, DataRowVersion.Default, null));
return cmd;
}
/// <summary>
/// close the connection.
/// </summary>
public void Close()
{
if (con != null)
con.Close();
}
/// <summary>
/// Release resources.
/// </summary>
public void Dispose()
{
// make sure connection is closed
if (con != null)
{
con.Dispose();
con = null;
}
}
//Note execute nonquery requires you to close()
public int RunProc(string procName)
{
SqlCommand cmd = CreateCommand(procName, null);
cmd.ExecuteNonQuery();
this.Close();
return (int)cmd.Parameters["ReturnValue"].Value;
}
Its a bit of a mess and probs not worth it - but its all there now if its any
good to anyone. It's all from PetShop app anyway (altered a bit)
Probs shouldn't have sent it.