Exemplo n.º 1
0
        private static void InsertEmployee(
            ref int ID,
            string Name,
            string Title,
            string Address,
            decimal Salary,
            DateTime JoinedDate,
            byte?Children)
        {
            try
            {
                string str = "CREATE PROCEDURE [dbo].[sp_InsertEmp](";
                str += "@ID int OUTPUT," + "@Name nvarchar(30),";
                str += "@Title varchar(20)," + "@Address varchar(30),";
                str += "@Salary money," + "@JoinedDate datetime,";
                str += "@Children tinyint)";

                // Parse the stored procedure signature
                SPSignature signature = new SPSignature(str);

                SPCaller caller = new SPCaller(signature);
                caller.ConnectionStr = ConnectionStr;

                Output outputID = new Output(ID);
                caller.CallVoidProc("[dbo].[sp_InsertEmp]",
                                    outputID, Name, Title, Address, Salary, JoinedDate, Children);

                ID = outputID.GetInt();
            }
            catch (System.Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }
        public static void InsertEmployee(
            ref int ID,
            string Name,
            string Title,
            string Address,
            decimal Salary,
            DateTime JoinedDate,
            byte?Children)
        {
            try
            {
                string str = "CREATE PROCEDURE [dbo].[sp_InsertEmp](";
                str += "@ID int OUTPUT," + "@Name nvarchar(30),";
                str += "@Title varchar(20)," + "@Address varchar(30),";
                str += "@Salary money," + "@JoinedDate datetime,";
                str += "@Children tinyint)";

                // Parse the stored procedure signature
                SPSignature signature = new SPSignature(str);

                string location = System.Reflection.Assembly.GetExecutingAssembly().Location;
                string dir      = System.IO.Path.GetDirectoryName(location);
                string xmlPath  = System.IO.Path.Combine(dir, "signature.xml");

                signature.Save(xmlPath);
                SPSignature signature2 = new SPSignature();
                signature2.Load(xmlPath);

                SPCaller caller = new SPCaller(signature2);
                caller.ConnectionStr = ConnectionStr;

                Output outputID = new Output(ID);
                caller.CallVoidProc("[dbo].[sp_InsertEmp]",
                                    outputID, Name, Title, Address, Salary, JoinedDate, Children);

                ID = outputID.GetInt();
            }
            catch (System.Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }