Note that there are some explanatory texts on larger screens.

plurals
  1. POReceiving an error when calling a public class
    primarykey
    data
    text
    <p>Here's the error: </p> <blockquote> <p>An object reference is required for a non-static field, method, or property 'ArchiCapture.Models.dbConnection.runSproc(string[], string[], string)'</p> </blockquote> <p>It appears at the call dt = dbConnection.runSproc(paramName, paramValue, "pr_select_employee_by_id");</p> <p>I'm trying to develop a class that will call SPROCs. Here's my class.</p> <pre><code>namespace ArchiCapture.Models { public class dbConnection { public DataTable runSproc(string[] paramName, string[] paramValue, string sproc) { SqlConnection conn = null; DataTable dt = new DataTable(); SqlDataReader reader = null; try { string connStr = ConfigurationManager.ConnectionStrings["AC2012"].ConnectionString; using (conn = new SqlConnection(connStr)) { SqlCommand cmd = new SqlCommand(sproc, conn); cmd.CommandType = CommandType.StoredProcedure; for (int x = 0; x &lt; paramName.Count(); x++) { cmd.Parameters.Add(new SqlParameter(paramName[x], paramValue[x])); } conn.Open(); reader = cmd.ExecuteReader(); dt.Load(reader); return dt; } } catch (SqlException e) { throw (e); } catch (Exception ex) { throw (ex); } finally { if (conn != null) { conn.Close(); } if (reader != null) { reader.Close(); } } } } } </code></pre> <p>And here's how I'm calling it..</p> <pre><code> DataTable dt = new DataTable(); string[] paramName = new string[1] { "@employee_id" }; string[] paramValue = new string[1] { searchEngine.Value }; dt = dbConnection.runSproc(paramName, paramValue, "pr_select_employee_by_id"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload