I have an SQL Stored Procedure that is outputting (using scope_indentity ) the PersonID after a record is inserted into the table. I need this outputted value to be returned to my application. I have tried the following but I am getting errors..."Non-invocable member 'System.Data.Sq lClient.SqlComm and.Parameters' cannot be used like a method." on the line "cmd.Parameters ("@PersonID").D irection = ParameterDirect ion.Output;"
Code:
public long InsertPerson() { SqlConnection conn = null; SqlDataReader rdr = null; long lngPersonID = 0; try { conn = new SqlConnection("Server=Global2;DataBase=PictureCapture;Integrated Security=True"); conn.Open(); SqlCommand cmd = new SqlCommand("InsertPerson", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@practicecode", this.practicecode)); cmd.Parameters.Add(new SqlParameter("@mrn", this.mrn)); cmd.Parameters.Add(new SqlParameter("@fname", this.fname)); cmd.Parameters.Add(new SqlParameter("@lname", this.lname)); cmd.Parameters.Add(new SqlParameter("@dob", this.dob)); cmd.Parameters.Add(new SqlParameter("@ssn", this.ssn)); cmd.Parameters.Add(new SqlParameter("@PersonID", 0)); cmd.Parameters("@PersonID").Direction = ParameterDirection.Output; rdr = cmd.ExecuteScalar(); lngPersonID = Convert.ToInt32(cmd.Parameters("@PersonID").Value); } finally { if (conn != null) { conn.Close(); } if (rdr != null) { rdr.Close(); } } return lngPersonID; }
Comment