Click here to Skip to main content
15,888,293 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: data access Pin
Abhishek Sur23-Sep-09 12:17
professionalAbhishek Sur23-Sep-09 12:17 
GeneralRe: data access Pin
N a v a n e e t h23-Sep-09 15:47
N a v a n e e t h23-Sep-09 15:47 
GeneralRe: data access Pin
Abhishek Sur23-Sep-09 23:28
professionalAbhishek Sur23-Sep-09 23:28 
GeneralRe: data access Pin
N a v a n e e t h24-Sep-09 5:03
N a v a n e e t h24-Sep-09 5:03 
GeneralRe: data access Pin
Abhishek Sur25-Sep-09 12:16
professionalAbhishek Sur25-Sep-09 12:16 
GeneralRe: data access Pin
raquidd2230-Sep-09 6:27
raquidd2230-Sep-09 6:27 
AnswerRe: data access Pin
N a v a n e e t h23-Sep-09 15:44
N a v a n e e t h23-Sep-09 15:44 
GeneralRe: data access Pin
raquidd2224-Sep-09 6:38
raquidd2224-Sep-09 6:38 
thank for all
thanks N a v a n e e t h


i understand all coment about byval o vbyref, first time i see the out parameter in c#.
the code original is and working, i tested.

public class PersonDataService
           public void Person_Save(ref int personID, string nameFirst, string nameLast, DateTime dob)
        {
            SqlCommand cmd;
            ExecuteNonQuery(out cmd, "Person_Save",
                CreateParameter("@PersonID", SqlDbType.Int, personID, ParameterDirection.InputOutput),
                CreateParameter("@NameFirst", SqlDbType.NVarChar, nameFirst),
                CreateParameter("@NameLast", SqlDbType.NVarChar, nameLast),
                CreateParameter("@DOB", SqlDbType.DateTime, dob));            
            personID = (int)cmd.Parameters["@PersonID"].Value;
            cmd.Dispose();
        }



and the class

        protected void ExecuteNonQuery(string procName,
            params IDataParameter[] procParams)
        {
            SqlCommand cmd;
            ExecuteNonQuery(out cmd, procName, procParams);
        }
protected void ExecuteNonQuery(out SqlCommand cmd, string procName,
            params IDataParameter[] procParams)
        {
            //Method variables
            SqlConnection cnx = null;
            cmd = null;  //Avoids "Use of unassigned variable" compiler error

            try
            {
                //Setup command object
                cmd = new SqlCommand(procName);
                cmd.CommandType = CommandType.StoredProcedure;
                for (int index = 0; index < procParams.Length; index++)
                {
                    cmd.Parameters.Add(procParams[index]);
                }

                //Determine the transaction owner and process accordingly
                if (_isOwner)
                {
                    cnx = new SqlConnection(GetConnectionString());
                    cmd.Connection = cnx;
                    cnx.Open();
                }
                else
                {
                    cmd.Connection = _txn.Connection;
                    cmd.Transaction = _txn;
                }

                //Execute the command
                cmd.ExecuteNonQuery();
            }
            catch
            {
                throw;
            }
            finally
            {
                if (_isOwner)
                {
                    cnx.Dispose(); //Implicitly calls cnx.Close()
                }
                if (cmd != null) cmd.Dispose();
            }
        }


regards,
MS
GeneralRe: data access Pin
raquidd2224-Sep-09 7:06
raquidd2224-Sep-09 7:06 
GeneralRe: data access Pin
Abhishek Sur25-Sep-09 12:15
professionalAbhishek Sur25-Sep-09 12:15 
Questionquestions Pin
hasani200723-Sep-09 10:25
hasani200723-Sep-09 10:25 
AnswerRe: questions Pin
Abhishek Sur23-Sep-09 10:32
professionalAbhishek Sur23-Sep-09 10:32 
QuestionNewsletter App Pin
kruegersck23-Sep-09 10:07
kruegersck23-Sep-09 10:07 
AnswerRe: Newsletter App Pin
Abhishek Sur23-Sep-09 10:26
professionalAbhishek Sur23-Sep-09 10:26 
QuestionObject does not support this property or method Pin
dptalt23-Sep-09 8:04
dptalt23-Sep-09 8:04 
AnswerRe: Object does not support this property or method Pin
Abhishek Sur23-Sep-09 9:23
professionalAbhishek Sur23-Sep-09 9:23 
Questioniframe .. src Pin
Hemant Thaker23-Sep-09 4:45
Hemant Thaker23-Sep-09 4:45 
AnswerRe: iframe .. src Pin
Abhishek Sur23-Sep-09 5:47
professionalAbhishek Sur23-Sep-09 5:47 
QuestionRe: iframe .. src Pin
Hemant Thaker23-Sep-09 6:40
Hemant Thaker23-Sep-09 6:40 
AnswerRe: iframe .. src Pin
Abhijit Jana23-Sep-09 6:44
professionalAbhijit Jana23-Sep-09 6:44 
GeneralRe: iframe .. src Pin
Abhishek Sur23-Sep-09 8:27
professionalAbhishek Sur23-Sep-09 8:27 
GeneralRe: iframe .. src Pin
Abhijit Jana23-Sep-09 9:10
professionalAbhijit Jana23-Sep-09 9:10 
QuestionRe: iframe .. src Pin
Hemant Thaker23-Sep-09 9:32
Hemant Thaker23-Sep-09 9:32 
AnswerRe: iframe .. src Pin
Abhishek Sur23-Sep-09 9:55
professionalAbhishek Sur23-Sep-09 9:55 
GeneralRe: iframe .. src Pin
Abhishek Sur23-Sep-09 9:50
professionalAbhishek Sur23-Sep-09 9:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.