public static int Delete(bMemberPhotos objMemberPhotos, SqlConnection sqlConn, SqlTransaction sqlTran) { // construct new connection and command objects SqlConnection conn = sqlConn; SqlCommand cmd = DBHelper.getSprocCmd("sprocMemberPhotosDeleteByParams", conn); cmd.Transaction = sqlTran; SqlParameter param; // add return value param param = new SqlParameter("@RETURN_VALUE", SqlDbType.Int); param.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(param); // Add params param = new SqlParameter("@MemberPhotoID", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intMemberPhotoID; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoName", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoName; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoDesc", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoDesc; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoUrl", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoUrl; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoType", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intPhotoType; cmd.Parameters.Add(param); param = new SqlParameter("@AlbumID", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intAlbumID; cmd.Parameters.Add(param); param = new SqlParameter("@MemberID", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intMemberID; cmd.Parameters.Add(param); // Execute command cmd.ExecuteNonQuery(); // get return value int retValue = 0; try { // get return value of the sproc retValue = (int)cmd.Parameters["@RETURN_VALUE"].Value; } catch (System.Exception) { // catch all possible exceptions retValue = 0; // set retValue To 0 (all ok) } return(retValue); }
public static int Insert(bMemberPhotos objMemberPhotos) { // construct new connection and command objects SqlConnection conn = DBHelper.getConnection(); SqlCommand cmd = DBHelper.getSprocCmd("sprocMemberPhotosInsert", conn); SqlParameter param; // Add return value param param = new SqlParameter("@RETURN_VALUE", SqlDbType.Int); param.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(param); // Add params param = new SqlParameter("@MemberPhotoID", SqlDbType.Int); param.Direction = ParameterDirection.Input; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoName", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoName; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoDesc", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoDesc; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoUrl", SqlDbType.NVarChar); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_strPhotoUrl; cmd.Parameters.Add(param); param = new SqlParameter("@PhotoType", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intPhotoType; cmd.Parameters.Add(param); param = new SqlParameter("@AlbumID", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intAlbumID; cmd.Parameters.Add(param); param = new SqlParameter("@MemberID", SqlDbType.Int); param.Direction = ParameterDirection.Input; param.Value = objMemberPhotos.m_intMemberID; cmd.Parameters.Add(param); // open connection conn.Open(); // Execute command cmd.ExecuteNonQuery(); // get return value int retValue = 0; try { // get return value of the sproc retValue = (int)cmd.Parameters["@RETURN_VALUE"].Value; } catch (System.Exception) { // catch all possible exceptions retValue = 0; // set retValue To 0 (all ok) } // close connection conn.Close(); // set dirty flag To false if (retValue != 0) { objMemberPhotos.MemberPhotoID = retValue; } return(retValue); }