NativeAdoTestObjectDao.cs :  » Inversion-of-Control-Dependency-Injection » Spring.net » Spring » Data » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Inversion of Control Dependency Injection » Spring.net 
Spring.net » Spring » Data » NativeAdoTestObjectDao.cs
#region Imports

using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Spring.Objects;

#endregion

namespace Spring.Data{
    public class NativeAdoTestObjectDao : ITestObjectDao
    {
        private String connectionString;

        public string ConnectionString
        {
            get { return connectionString; }
            set { connectionString = value; }
        }


        public IList ExplicitTx()
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    
                    using (SqlTransaction transaction = connection.BeginTransaction())
                    {
                        using (SqlCommand command = new SqlCommand("sql"))
                        {
                            command.Connection = connection;
                            command.Transaction = transaction;

                            /*
                             *   dbParameters.Add("savings", DbType.Decimal).Value = b.Savings.AsDecimal();
  dbParameters.Add("accountId", DbType.Int).Value = account.EntityId;
  dbParameters.Add("name", DbType.String).Value = b.Name;
                             */
                            command.Parameters.Add("@savings", SqlDbType.Decimal).Value = 1;// = b.Savings.AsDecimal();
                            command.Parameters.Add("@accountId", SqlDbType.Int).Value = 2;
                            command.Parameters.Add("@name", SqlDbType.NVarChar, 40).Value = 3;
                            command.ExecuteNonQuery();
                            //foreach (Benificiary b in Account.Beneficiaries)
                            //{
                                
                            //}

                            transaction.Commit();
                        }
                    }
                }
            } catch (Exception)
            {
                //log exception and rethrow
            }
            return null;
        }

        public IList FindAllPeople()
        {
            IList results = new ArrayList();
            try
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    string sql = "select Name, Age from ...";

                    using (SqlCommand command = new SqlCommand(sql, connection))
                    {
                        connection.Open();
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                //process the result set - populate Person object, add to array
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                //throw application exception
            }
            return results;
        }

        public void Create2(string name, int age)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                String sql =
                    String.Format("insert into TestObjects(Age, Name) " +
                                  "VALUES ({0}, '{1}')",
                                  age, name);

                using (SqlCommand cmd = new SqlCommand(sql, connection))
                {
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
            }
        }

        public void Create(string name, int age)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlParameter p1 = new SqlParameter("name", SqlDbType.NVarChar);
                p1.Value = "asdf";

                /*
                string strSql = "insert into TestObjects(Age,Name) values (@Age,@Name)";
                
                
                SqlCommand comm = connection.CreateCommand();
                comm.CommandText = strSql;
                SqlParameter p1 = new SqlParameter();
                p1.ParameterName = "@Age";
                p1.Value = age;
                
                SqlParameter p2 = new SqlParameter();
                p2.ParameterName = "@Name";
                p2.Value = name;
                
                comm.Parameters.Add(p1);
                comm.Parameters.Add(p2);
                
                */

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat(
                    "insert into TestObjects(Age, Name) VALUES ({0}, '{1}')",
                    age, name);

                SqlCommand comm = connection.CreateCommand();
                comm.CommandText = sb.ToString();


                connection.Open();
                comm.ExecuteNonQuery();
            }
        }

        public void Update(TestObject to)
        {
            // TODO:  Add NativeAdoTestObjectDao.Update implementation
        }

        public void Delete(string name)
        {
            // TODO:  Add NativeAdoTestObjectDao.Delete implementation
        }

        public TestObject FindByName(string name)
        {
            // TODO:  Add NativeAdoTestObjectDao.FindByName implementation
            return null;
        }

        public System.Collections.IList FindAll()
        {
            // TODO:  Add NativeAdoTestObjectDao.FindAll implementation
            return null;
        }

        public int GetCount()
        {
            // TODO:  Add NativeAdoTestObjectDao.GetCount implementation
            return 0;
        }

        public int GetCountByDelegate()
        {
            // TODO:  Add NativeAdoTestObjectDao.GetCountByDelegate implementation
            return 0;
        }

        public int GetCount(int lowerAgeLimit)
        {
            throw new NotImplementedException();
        }

        public int GetCount(int lowerAgeLimit, string name)
        {
            throw new NotImplementedException();
        }

        public int GetCountByAltMethod(int lowerAgeLimit)
        {
            throw new NotImplementedException();
        }

        public int GetCountByCommandSetter(int lowerAgeLimit)
        {
            throw new NotImplementedException();
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.