<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-493733235295437780</atom:id><lastBuildDate>Mon, 08 Jun 2026 12:42:08 +0000</lastBuildDate><category>.NET</category><category>ASP.NET</category><category>CsharpGears Framework</category><category>C#</category><category>Object Relational Mapping</category><category>bind SQL to C#</category><category>ANDROID</category><category>C# Gears Framework</category><category>Web service</category><category>XML</category><category>ksoap</category><category>C# free class libraries</category><category>Logger</category><category>array</category><category>Business Access Layer (BAL)</category><category>Data Access Layer (DAL)</category><category>Database</category><category>Database Access</category><category>Database Logger</category><category>N-Tier Architecture</category><category>RSS</category><category>SQL</category><category>stored procedures</category><category>CommitableTransaction</category><category>Complex object</category><category>Decorator Design Pattern</category><category>Derive Parameters</category><category>Direct mapping from SQL to C#</category><category>E-mail</category><category>Images</category><category>Log4Net</category><category>MySQL</category><category>MySQL DataProvider</category><category>Open Source</category><category>RSS Builder</category><category>RSS feed</category><category>SQL Transactions</category><category>URL rewrite</category><category>WSDL</category><category>code examples</category><category>comments</category><category>easy db access</category><category>encourage</category><category>free code examples. class libraries</category><category>interface</category><category>ksoap tutorial android xml webservice web-service ksoap2 .NET</category><category>marshal</category><category>marshaling</category><category>objects</category><category>output parameters</category><category>see sharp</category><title>See Sharp Gears</title><description>Best Programming Practices &amp;amp; Helping other Developers</description><link>http://seesharpgears.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>18</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-7321526767651120513</guid><pubDate>Thu, 25 Nov 2010 10:02:00 +0000</pubDate><atom:updated>2011-04-01T12:53:24.663+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ksoap tutorial android xml webservice web-service ksoap2 .NET</category><title>Basic KSOAP Android Tutorial</title><description>&lt;div style=&quot;padding-right:10px;float:left&quot;&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 300x250, created 11/25/10 */
google_ad_slot = &quot;1104373824&quot;;
google_ad_width = 300;
google_ad_height = 250;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;/div&gt;&lt;p&gt;This is a basic KSOAP Android tutorial - here I will show you how to get started with KSOAP on Android. As you may know, we often want to access Web services via hand-held devices, and most likely you will run into trouble parsing the WSDL and the SOAP messages. Since I come from a .NET background, once I started developing on Android, I realized how much work has been Visual Studio doing for me.&lt;br /&gt;
&lt;br /&gt;
That thought took me to search for a framework or library to help me consume Web Services with Android. I ran into KSOAP2, which seemed like a good library, but unfortunately, very badly documented for most scenarios, like passing or returning complex objects, working with arrays of objects or even working with dates. &lt;br /&gt;
&lt;/p&gt;&lt;br /&gt;
&lt;div style=&quot;margin-top:20px;clear:both;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
All of this I needed to find out by myself and this is why I decided to write this tutorial. So, let&#39;s begin.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Getting Started with KSOAP on Android&lt;/h3&gt;&lt;br /&gt;
First things first, so you should now go ahead and download the KSOAP library from &lt;strike&gt;Sourceforge&lt;/strike&gt; Google code (&lt;strong&gt;*UPDATE*&lt;/strong&gt; thanks Freddy):&lt;br /&gt;
&lt;a href=&quot;http://code.google.com/p/ksoap2-android/downloads/detail?name=ksoap2-android-assembly-2.4-jar-with-dependencies.jar&amp;can=2&amp;q=
&quot; rel=&quot;nofollow&quot;&gt;http://code.google.com/p/ksoap2-android/downloads/detail?name=ksoap2-android-assembly-2.4-jar-with-dependencies.jar&amp;can=2&amp;q=&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Then copy and paste the KSOAP library in the folder where your Android project will reside. Open Eclipse, start a new Android Project, right-click on the project&#39;s name and choose Properties, like this:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRjezh5YsWUe5T8eH9VDQ_i4r9bm9Ql8hp4oqndDQs8qRCJX990Umyqh0ecZ0zffyPXNyznYt2ciCgk_ZMspu7JOTfeUDkUWz7njkLMuBUWuiNUAIg421WAHh7_FYsae3PR2QZFZwrPL6e/s1600/ksoap+right+click.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRjezh5YsWUe5T8eH9VDQ_i4r9bm9Ql8hp4oqndDQs8qRCJX990Umyqh0ecZ0zffyPXNyznYt2ciCgk_ZMspu7JOTfeUDkUWz7njkLMuBUWuiNUAIg421WAHh7_FYsae3PR2QZFZwrPL6e/s320/ksoap+right+click.jpg&quot; width=&quot;207&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
The next thing you need to do is to Add the KSOAP .JAR into the Android Project:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj5T3_rwMsvEq3vF4JMa3qaDL5Rl_j5QCrmWcYytjvKYNWqWn7gNIa56h4x1pT-uFJ5c0SnBuutBIHmx3XHhPRgtLD3pBNyIB3aDKTJOi7s3Mcg9Po6z_IWZjajW3UYnn6FnGbXVVPHgqz/s1600/Add+JAR.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;229&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj5T3_rwMsvEq3vF4JMa3qaDL5Rl_j5QCrmWcYytjvKYNWqWn7gNIa56h4x1pT-uFJ5c0SnBuutBIHmx3XHhPRgtLD3pBNyIB3aDKTJOi7s3Mcg9Po6z_IWZjajW3UYnn6FnGbXVVPHgqz/s320/Add+JAR.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Go ahead an press Add JARs... button. Then navigate to the folder where your KSOAP library is and select it. Once you have this done, you are ready to start working with your Web Service library.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Simple Web Service Calls with KSOAP&lt;/h3&gt;&lt;br /&gt;
First, let&#39;s take a look at our web service call in Visual Studio:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;[WebService(Namespace = &lt;span class=&quot;str&quot;&gt;&quot;http://vladozver.org/&quot;&lt;/span&gt;)]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; SimpleWebServices : System.Web.Services.WebService
{
      [WebMethod]
      &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; GetSumOfTwoInts(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; Operand1, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; Operand2 )
      {
         &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Operand1 + Operand2;
      }
}&lt;/pre&gt;&lt;br /&gt;
The service is deployed on my local machine which is on the address: 192.168.1.3. Pay attention on the ending &quot;/&quot; in the Namespace.&lt;br /&gt;
&lt;br /&gt;
Now, KSOAP finally.&lt;br /&gt;
&lt;br /&gt;
KSOAP relies on a basic object called SoapObject. For this SoapObject, there are 3 variables that are important:&lt;br /&gt;
The Web Service Namespace&lt;br /&gt;
The Web Service Method Name&lt;br /&gt;
The Web Service URL&lt;br /&gt;
&lt;br /&gt;
There is another extra variable which is important and is called SOAP_ACTION, but that is basically a concatenation of the Namespace and Method name:&lt;br /&gt;
&lt;br /&gt;
SOAP_ACTION = NAMESPACE + METHOD_NAME;&lt;br /&gt;
&lt;br /&gt;
For now we will create 3 strings for the respective variables:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;String NAMESPACE = &lt;span class=&quot;str&quot;&gt;&quot;http://vladozver.org/&quot;&lt;/span&gt;;
        String METHOD_NAME = &lt;span class=&quot;str&quot;&gt;&quot;GetSumOfTwoInts&quot;&lt;/span&gt;;
        String SOAP_ACTION = &lt;span class=&quot;str&quot;&gt;&quot;http://vladozver.org/GetSumOfTwoInts&quot;&lt;/span&gt;;
        String URL = &lt;span class=&quot;str&quot;&gt;&quot;http://192.168.1.3/VipEvents/Services/BasicServices.asmx&quot;&lt;/span&gt;;
&lt;/pre&gt;&lt;br /&gt;
Then we will create the SoapObject:&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;SoapObject Request = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapObject(NAMESPACE, METHOD_NAME);
&lt;/pre&gt;&lt;br /&gt;
Parameters in KSOAP are passed via PropertyInfo class instances, so we will create some of those:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;PropertyInfo pi = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PropertyInfo();
        pi.setName(&lt;span class=&quot;str&quot;&gt;&quot;Operand1&quot;&lt;/span&gt;);
        pi.setValue(2);
        pi.setType(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;.&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;);
        Request.addProperty(pi);

        PropertyInfo pi2 = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PropertyInfo();
        pi2.setName(&lt;span class=&quot;str&quot;&gt;&quot;Operand2&quot;&lt;/span&gt;);
        pi2.setValue(5);
        pi2.setType(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;.&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;);
        Request.addProperty(pi2);&lt;/pre&gt;&lt;br /&gt;
Then we will create another important KSOAP object, and that is Soap Envelope:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;SoapSerializationEnvelope envelope = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;
        envelope.setOutputSoapObject(Request);&lt;/pre&gt;&lt;br /&gt;
Because our Web Service is .NET based, we need to set the .dotNet property to true. &lt;br /&gt;
Next step is to create a Transport object:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;AndroidHttpTransport androidHttpTransport = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AndroidHttpTransport(URL);&lt;/pre&gt;&lt;br /&gt;
Lastly, we need to invoke the web service and obtain the result:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;try&lt;/span&gt;
            {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                SoapObject response = (SoapObject)envelope.getResponse();
                &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; result =  Integer.parseInt(response.getProperty(0).toString());
            }
            &lt;span class=&quot;kwrd&quot;&gt;catch&lt;/span&gt;(Exception e)
            {
                e.printStackTrace();
            }&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
That is basically it! I hope you will find this tutorial helpful, as I see that many people are looking for a simple Getting started tutorial on KSOAP Android. For more advanced usage of KSOAP, refer to my other posts on this topic.</description><link>http://seesharpgears.blogspot.com/2010/11/basic-ksoap-android-tutorial.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRjezh5YsWUe5T8eH9VDQ_i4r9bm9Ql8hp4oqndDQs8qRCJX990Umyqh0ecZ0zffyPXNyznYt2ciCgk_ZMspu7JOTfeUDkUWz7njkLMuBUWuiNUAIg421WAHh7_FYsae3PR2QZFZwrPL6e/s72-c/ksoap+right+click.jpg" height="72" width="72"/><thr:total>453</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-2303697297729047195</guid><pubDate>Thu, 11 Nov 2010 07:37:00 +0000</pubDate><atom:updated>2010-11-11T08:37:40.036+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ANDROID</category><category domain="http://www.blogger.com/atom/ns#">code examples</category><category domain="http://www.blogger.com/atom/ns#">interface</category><category domain="http://www.blogger.com/atom/ns#">ksoap</category><category domain="http://www.blogger.com/atom/ns#">marshal</category><category domain="http://www.blogger.com/atom/ns#">marshaling</category><category domain="http://www.blogger.com/atom/ns#">Web service</category><category domain="http://www.blogger.com/atom/ns#">XML</category><title>Implementing KSOAP Marshal Interface</title><description>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
Another poorly documented spot in KSOAP: marshaling arguments. In KSOAP, you need to implement an interface called Marshal so that the XML parser would know how to serialize and deserialize objects you are trying to pass through the web service. &lt;br /&gt;
&lt;br /&gt;
Strangely enough, object types like &quot;double&quot; and &quot;Date&quot; need to be manually marshaled! This is why I decided my code examples to show how to marshal dates and doubles. So here it goes:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;package Marshals;

import java.io.IOException;

import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
&lt;span class=&quot;rem&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;* &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;* @author Vladimir&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;* Used to marshal Doubles - crucial to serialization for SOAP&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;*/&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; MarshalDouble implements Marshal 
{


    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Object readInstance(XmlPullParser parser, String &lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt;, String name, 
            PropertyInfo expected) throws IOException, XmlPullParserException {
        
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Double.parseDouble(parser.nextText());
    }


    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; register(SoapSerializationEnvelope cm) {
         cm.addMapping(cm.xsd, &lt;span class=&quot;str&quot;&gt;&quot;double&quot;&lt;/span&gt;, Double.&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;);
        
    }


    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; writeInstance(XmlSerializer writer, Object obj) throws IOException {
           writer.text(obj.toString());
        }
    
}
&lt;/pre&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
As you can see, the code here is so trivial that I am honestly surprised why it does not come out of the box like it does for ints.&lt;br /&gt;
The next example shows how to Marhsal Dates with KSOAP:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;package Marshals;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.kobjects.isodate.IsoDate;
import org.ksoap2.serialization.Marshal;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

&lt;span class=&quot;rem&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * @author Vladimir&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * Used to marshal Dates - crucial to serialization for SOAP&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; MarshalDate implements Marshal
{

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Object readInstance(XmlPullParser parser, String &lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt;, String name, 
                PropertyInfo expected) throws IOException, XmlPullParserException {
            
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; IsoDate.stringToDate(parser.nextText(), IsoDate.DATE_TIME);
            
            
        }


        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; register(SoapSerializationEnvelope cm) {
             cm.addMapping(cm.xsd, &lt;span class=&quot;str&quot;&gt;&quot;DateTime&quot;&lt;/span&gt;, Date.&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;);
            
        }


        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; writeInstance(XmlSerializer writer, Object obj) throws IOException {
             writer.text(IsoDate.dateToString((Date) obj, IsoDate.DATE_TIME));
            }
    
}
&lt;/pre&gt;&lt;br /&gt;
As you probably assume, in order to tell KSOAP how to use the marshaling, you need to use the register() method in the following manner:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;String MethodName = &lt;span class=&quot;str&quot;&gt;&quot;GetEventById&quot;&lt;/span&gt;;
SoapObject request = GetSoapObject(MethodName);
AddProperty(request, Event);
SoapSerializationEnvelope envelope = GetEnvelope(request);
        
envelope.addMapping(NAMESPACE, &lt;span class=&quot;str&quot;&gt;&quot;Event&quot;&lt;/span&gt;,Event.getClass());

MarshalDate md = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; MarshalDate();
md.register(envelope);
       
SoapObject response =  MakeCall(URL,envelope,NAMESPACE,MethodName);&lt;/pre&gt;&lt;br /&gt;
Basically that is all you need to get started with KSOAP marshaling.&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2010/11/implementing-ksoap-marshal-interface.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>90</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-2062624401371728616</guid><pubDate>Thu, 04 Nov 2010 15:14:00 +0000</pubDate><atom:updated>2010-11-04T16:16:29.610+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ANDROID</category><category domain="http://www.blogger.com/atom/ns#">array</category><category domain="http://www.blogger.com/atom/ns#">ksoap</category><category domain="http://www.blogger.com/atom/ns#">Web service</category><category domain="http://www.blogger.com/atom/ns#">XML</category><title>Returning Array of Primitive Types with KSOAP</title><description>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
KSOAP until recently had an issue with returning an array of primitive types. With the new patch the issue is solved. If you haven&#39;t downloaded the newest version of  &lt;br /&gt;
&lt;a href=&quot;https://github.com/mosabua/ksoap2-android/tree/&quot; rel=&quot;nofollow&quot;&gt;KSOAP available on GitHub&lt;/a&gt;, you can use the following snippet:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;SoapObject request = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapObject(NAMESPACE, METHOD_NAME);
            SoapSerializationEnvelope envelope =
            &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapSerializationEnvelope(SoapEnvelope.VER11);
            &lt;span class=&quot;rem&quot;&gt;//envelope.dotNet = true;&lt;/span&gt;
            envelope.setOutputSoapObject(request);
            AndroidHttpTransport androidHttpTransport = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AndroidHttpTransport(URL);
        androidHttpTransport.call(SOAP_ACTION, envelope);

                KvmSerializable ks = (KvmSerializable)envelope.bodyIn;
                &lt;span class=&quot;kwrd&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; i=0;i&amp;lt;ks.getPropertyCount();i++)
                {
                   ks.getProperty(i); &lt;span class=&quot;rem&quot;&gt;//if complex type is present then you can cast this to SoapObject and if primitive type is returned you can use toString() to get actuall value.&lt;/span&gt;
                }
&lt;/pre&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
This code was written by &lt;a href=&quot;http://code.google.com/u/nebe.daredevil/&quot; rel=&quot;nofollow&quot;&gt;nebe.daredevil&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
If anyone else is having trouble to return array of primitive types with KSOAP, might consider the &lt;a href=&quot;http://code.google.com/p/ksoap2-android/issues/detail?id=24&quot; rel=&quot;nofollow&quot;&gt;issue thread on Google Code&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I hope the agony with KSOAP is near an end with this.&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2010/11/returning-array-of-primitive-types-with.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>28</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-6640450678910607834</guid><pubDate>Tue, 26 Oct 2010 09:18:00 +0000</pubDate><atom:updated>2010-11-01T18:14:14.811+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ANDROID</category><category domain="http://www.blogger.com/atom/ns#">array</category><category domain="http://www.blogger.com/atom/ns#">ksoap</category><category domain="http://www.blogger.com/atom/ns#">objects</category><category domain="http://www.blogger.com/atom/ns#">Web service</category><category domain="http://www.blogger.com/atom/ns#">XML</category><title>Web Service That Returns An Array of Objects With KSOAP</title><description>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
In my previous post, I wrote about an example of passing &lt;a href=&quot;http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html&quot; title=&quot;working with complex objects with KSOAP&quot;&gt;complex objects with KSOAP&lt;/a&gt;. In this post, I will write about &lt;b&gt;returning arrays of objects with KSOAP&lt;/b&gt;.&lt;br /&gt;
If you want to know how to write a method that &lt;b&gt;returns an array of complex objects&lt;/b&gt;, look at this code:&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; Category[] GetAllCategories()
    {
        String MethodName = &lt;span class=&quot;str&quot;&gt;&quot;GetAllCategories&quot;&lt;/span&gt;;
        SoapObject response = InvokeMethod(URL,MethodName);
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RetrieveFromSoap(response);
        
    }&lt;/pre&gt;&lt;br /&gt;
Where the function InvokeMethod is :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; SoapObject InvokeMethod(String URL,String MethodName)
    {
        SoapObject request = GetSoapObject(MethodName);
        SoapSerializationEnvelope envelope = GetEnvelope(request);
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt;  MakeCall(URL,envelope,NAMESPACE,MethodName);
    }&lt;/pre&gt;&lt;br /&gt;
GetSoapObject() and GetEnvelope() are:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; SoapObject GetSoapObject(String MethodName)
    {
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapObject(NAMESPACE,MethodName);
    }
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; SoapSerializationEnvelope GetEnvelope(SoapObject Soap)
    {
        SoapSerializationEnvelope envelope = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;
        envelope.setOutputSoapObject(Soap);
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; envelope;
    }&lt;/pre&gt;&lt;br /&gt;
MakeCall() is :&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @param URL - The complete URL where the web service resides &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @param Envelope - The envelope to be passed&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @param NAMESPACE - The web method namespace&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @param METHOD_NAME - The method name&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @return - SoapObject containing the resultset&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     */&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; SoapObject MakeCall(String URL, SoapSerializationEnvelope Envelope, String NAMESPACE, String METHOD_NAME)
    {
        AndroidHttpTransport androidHttpTransport = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AndroidHttpTransport(URL);
         &lt;span class=&quot;kwrd&quot;&gt;try&lt;/span&gt;
            {
                androidHttpTransport.call(NAMESPACE + METHOD_NAME, Envelope);
                SoapObject response = (SoapObject)Envelope.getResponse();
                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; response;
            }
         &lt;span class=&quot;kwrd&quot;&gt;catch&lt;/span&gt;(Exception e)
         {
             e.printStackTrace();
             
         }
         &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;
    }&lt;/pre&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
The most important part for retrieving the actual array of objects (in this case Category objects) is the following:&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @param soap - represents the entering Soap object&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     * @return returns the list of categories extracted from the response&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;     */&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; Category[] RetrieveFromSoap(SoapObject soap)
    {
        Category[] categories = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category[soap.getPropertyCount()];
        &lt;span class=&quot;kwrd&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; i = 0; i &amp;lt; categories.length; i++) {
            SoapObject pii = (SoapObject)soap.getProperty(i);
            Category category = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category();
            category.CategoryId = Integer.parseInt(pii.getProperty(0).toString());
            category.Name = pii.getProperty(1).toString();
            category.Description = pii.getProperty(2).toString();
            categories[i] = category;
        }
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; categories;
    }&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;NOTE&lt;/i&gt;&lt;/b&gt;: &lt;b&gt;Do not use VECTOR class type provided by KSOAP! It does not work.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I  really copy-pasted this from Eclipse, but hope it helps. Please write if you need more help. I hope I saved you at least some nerves.&lt;br /&gt;
&lt;br /&gt;
All the best.&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2010/10/web-service-that-returns-array-of.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>194</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-7610045047591729486</guid><pubDate>Sun, 24 Oct 2010 23:05:00 +0000</pubDate><atom:updated>2011-03-08T14:40:40.571+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ANDROID</category><category domain="http://www.blogger.com/atom/ns#">array</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">C# free class libraries</category><category domain="http://www.blogger.com/atom/ns#">Complex object</category><category domain="http://www.blogger.com/atom/ns#">ksoap</category><category domain="http://www.blogger.com/atom/ns#">Web service</category><category domain="http://www.blogger.com/atom/ns#">WSDL</category><category domain="http://www.blogger.com/atom/ns#">XML</category><title>KSoap Android Web Service Tutorial With Sample Code</title><description>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
A few months ago I was engaged into working with Android and I wanted to make an application that will communicate with the server via &lt;b&gt;.NET SOAP web services&lt;/b&gt;, but I soon found out that I will need a library to do the &quot;donkey work for me&quot;. Unfortunately, what Visual Studio was doing for me behind the scenes when importing WSDL document, was not present in Android. That means that, I would either parse the WSDL XML myself, or use an external library. After little search, I came up to &lt;b&gt;KSOAP&lt;/b&gt;, which looked like a promising library. But soon I got into lot of trouble to make it work. &lt;br /&gt;
Partly because there was no complete tutorial with the WHOLE sample WORKING code for passing &lt;b&gt;complex objects as parameters and/or arrays as return values&lt;/b&gt; (read this post for &lt;a href=&quot;http://seesharpgears.blogspot.com/2010/10/web-service-that-returns-array-of.html&quot;&gt;returning arrays of objects with KSOAP&lt;/a&gt; ), I spent many hours debugging exceptions which were filled with nulls and poor documentation in first place. &lt;br /&gt;
&lt;br /&gt;
Therefore I decided to publish the code I managed to make it work, so many lives will be saved :-) hopefully. I almost forgot about the idea of publishing my code, but today I got some e-mails from some of the Google groups where I was begging for help when I was developing the Android application. So, tortured developer souls, a complete working code for working with the &lt;b&gt;KSOAP&lt;/b&gt; library for Android:&lt;br /&gt;
&lt;br /&gt;
Scenario:&lt;br /&gt;
We will assume that we want to write a web service that retrieves the details about a given Category by its Id. So, in .NET, the service signature would be:&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;[Web Method]
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Category GetCategoryById(Category C);&lt;/pre&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
The class that we want to work with has 3 properties: CategoryId, Name and Description. But in order to use it with &lt;b&gt;KSOAP&lt;/b&gt;, we need to implement the &lt;b&gt;KvmSerializable&lt;/b&gt; interface (Code below is in &lt;b&gt;Java&lt;/b&gt;):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;package CommonObjects;

import java.util.Hashtable;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

&lt;span class=&quot;rem&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * @author Vladimir&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * Represents the Category object. KvmSerializable interface needs to be &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; * implemented for performing serialization.&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt; */&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Category implements KvmSerializable
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; CategoryId;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; String Name;
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; String Description;
    
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Category(){}
    

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Category(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; categoryId, String name, String description) {
        
        CategoryId = categoryId;
        Name = name;
        Description = description;
    }


    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Object getProperty(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; arg0) {
        
        &lt;span class=&quot;kwrd&quot;&gt;switch&lt;/span&gt;(arg0)
        {
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 0:
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; CategoryId;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 1:
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Name;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 2:
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Description;
        }
        
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; getPropertyCount() {
        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; 3;
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; getPropertyInfo(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; index, Hashtable arg1, PropertyInfo info) {
        &lt;span class=&quot;kwrd&quot;&gt;switch&lt;/span&gt;(index)
        {
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 0:
            info.type = PropertyInfo.INTEGER_CLASS;
            info.name = &lt;span class=&quot;str&quot;&gt;&quot;CategoryId&quot;&lt;/span&gt;;
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 1:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = &lt;span class=&quot;str&quot;&gt;&quot;Name&quot;&lt;/span&gt;;
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 2:
            info.type = PropertyInfo.STRING_CLASS;
            info.name = &lt;span class=&quot;str&quot;&gt;&quot;Description&quot;&lt;/span&gt;;
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;default&lt;/span&gt;:&lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        }
    }

    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; setProperty(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; index, Object &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;) {
        &lt;span class=&quot;kwrd&quot;&gt;switch&lt;/span&gt;(index)
        {
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 0:
            CategoryId = Integer.parseInt(&lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;.toString());
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 1:
            Name = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;.toString();
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; 2:
            Description = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;.toString();
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        &lt;span class=&quot;kwrd&quot;&gt;default&lt;/span&gt;:
            &lt;span class=&quot;kwrd&quot;&gt;break&lt;/span&gt;;
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
All methods in this class are members of the KvmSerializable Interface, and are used to tell &lt;b&gt;KSOAP&lt;/b&gt;how to map the properties, read them and write them.&lt;br /&gt;
&lt;br /&gt;
Now, the actual web service call:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; WebServiceCallExample()
    {
        String NAMESPACE = &lt;span class=&quot;str&quot;&gt;&quot;http://vladozver.org/&quot;&lt;/span&gt;;
        String METHOD_NAME = &lt;span class=&quot;str&quot;&gt;&quot;GetCategoryById&quot;&lt;/span&gt;;
        String SOAP_ACTION = &lt;span class=&quot;str&quot;&gt;&quot;http://vladozver.org/GetCategoryById&quot;&lt;/span&gt;;
        String URL = &lt;span class=&quot;str&quot;&gt;&quot;http://192.168.1.3/VipEvents/Services/CategoryServices.asmx&quot;&lt;/span&gt;;
        
        SoapObject Request = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapObject(NAMESPACE, METHOD_NAME);
        
        &lt;span class=&quot;rem&quot;&gt;/*&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * Create Category with Id to be passed as an argument&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * */&lt;/span&gt;
        Category C = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category();
        C.CategoryId = 1;
        
        &lt;span class=&quot;rem&quot;&gt;/*&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * Set the category to be the argument of the web service method&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * */&lt;/span&gt;
        PropertyInfo pi = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PropertyInfo();
        pi.setName(&lt;span class=&quot;str&quot;&gt;&quot;C&quot;&lt;/span&gt;);
        pi.setValue(C);
        pi.setType(C.getClass());
        Request.addProperty(pi);
        
        &lt;span class=&quot;rem&quot;&gt;/*&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * Set the web service envelope&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * */&lt;/span&gt;
        SoapSerializationEnvelope envelope = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;
        envelope.setOutputSoapObject(Request);
        
        envelope.addMapping(NAMESPACE, &lt;span class=&quot;str&quot;&gt;&quot;Category&quot;&lt;/span&gt;,&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category().getClass());
        AndroidHttpTransport androidHttpTransport = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AndroidHttpTransport(URL);
        &lt;span class=&quot;rem&quot;&gt;/*&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * Call the web service and retrieve result ... how luvly &amp;lt;3&lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * &lt;/span&gt;
&lt;span class=&quot;rem&quot;&gt;         * */&lt;/span&gt;
        &lt;span class=&quot;kwrd&quot;&gt;try&lt;/span&gt;
        {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
            C.CategoryId =  Integer.parseInt(response.getProperty(0).toString());
            C.Name =  response.getProperty(1).toString();
            C.Description = (String) response.getProperty(2).toString();
            TextView tv = (TextView)findViewById(R.id.TextView01);
            tv.setText(&lt;span class=&quot;str&quot;&gt;&quot;CategoryId: &quot;&lt;/span&gt; +C.CategoryId + &lt;span class=&quot;str&quot;&gt;&quot; Name: &quot;&lt;/span&gt; + C.Name + &lt;span class=&quot;str&quot;&gt;&quot; Description &quot;&lt;/span&gt; + C.Description);
        }
        &lt;span class=&quot;kwrd&quot;&gt;catch&lt;/span&gt;(Exception e)
        {
            e.printStackTrace();
        }
    }&lt;/pre&gt;&lt;br /&gt;
In order to use this code, make sure that you replace the first three variables in this method with your own. NOTE: The SOAP_ACTION could actually be computed as NAMESPACE + METHOD_NAME&lt;br /&gt;
&lt;br /&gt;
In the lines about the property info, I show how to actually pass a Category class complex object to &lt;b&gt;KSOAP&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;PropertyInfo pi = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PropertyInfo();
        pi.setName(&lt;span class=&quot;str&quot;&gt;&quot;Category&quot;&lt;/span&gt;);
        pi.setValue(C);
        pi.setType(C.getClass());
        Request.addProperty(pi);&lt;/pre&gt;&lt;br /&gt;
Regarding the return type, if your web method returns a complex object (such as ours), you need to tell &lt;b&gt;KSOAP&lt;/b&gt; how to handle the response. That is done with the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;envelope.addMapping(NAMESPACE, &lt;span class=&quot;str&quot;&gt;&quot;Category&quot;&lt;/span&gt;,&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category().getClass());&lt;/pre&gt;&lt;br /&gt;
This part of the code is the actual retrieval of the response:&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapObject response = (SoapObject)envelope.getResponse();
            C.CategoryId =  Integer.parseInt(response.getProperty(0).toString());
            C.Name =  response.getProperty(1).toString();
            C.Description = (String) response.getProperty(2).toString();&lt;/pre&gt;&lt;br /&gt;
For further reading, see my post about &lt;a href=&quot;http://seesharpgears.blogspot.com/2010/10/web-service-that-returns-array-of.html&quot;&gt;returning an array of complex objects with KSOAP&lt;/a&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>353</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-311523188043268152</guid><pubDate>Fri, 13 Nov 2009 15:10:00 +0000</pubDate><atom:updated>2009-11-13T16:10:54.810+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Derive Parameters</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><category domain="http://www.blogger.com/atom/ns#">stored procedures</category><title>CsharpGears: New class for Dynamic Discovery of Stored Procedure Parameters</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;Yesterday I wrote a new class in the &lt;b&gt;CSharpGears Framework&lt;/b&gt;. It is called &lt;b&gt;ParameterExtractor &lt;/b&gt;and it&#39;s purpose is to discover the parameters of a given stored procedure and retrieve them in a collection. This class utilizes the method &lt;b&gt;DeriveParameters &lt;/b&gt;in order to discover the parameters of the procedure and therefore, it can be only used with &lt;b&gt;SQL Server &lt;/b&gt;unfortunately, but since &lt;b&gt;SQL Server&lt;/b&gt; is quitte often a choice for database solution, this class might come in handy. The class also has caching capabilities, which can help saving performance since &lt;b&gt;DeriveParameters&lt;/b&gt; method causes a roundtrip to the database, and you certainly don&#39;t want to have two accesses to the database for each query. Because of that, it uses static caching and keeps the list of parameters in a collection for further reuse.&amp;nbsp; I have to admit that I am not certain about the thread safety of this operation, it is possible that a &lt;i&gt;lock&lt;/i&gt; statement is required as a critical region.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; My intention is to combine the &lt;b&gt;ParameterExtractor &lt;/b&gt;and integrate it with my N-tier architecture, so that it will help me automate the parameter adding process from my business objects to the stored procedures. The framework already supports the reverse process, namely to map the datareader&#39;s columns into a list of business objects ( you can read my post about &lt;a href=&quot;http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-object-relational.html&quot;&gt;Object relational mapping&lt;/a&gt; if you are interested). I hope that soon my project architecture will contain clean, separated code which is also easy to write, due to the generics of &lt;b&gt;C#&lt;/b&gt;.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&amp;nbsp; However, one should be aware of the limitations of this class, it only works with &lt;b&gt;SQL Server&lt;/b&gt;, and of course, it needs more memory to keep the stored procedure parameters, but its greatest adventage is that it is possible to write a code that will examine a business object and it will decide alone which attributes are needed to be mapped with which parameters - AUTOMATICALLY :).&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;blockquote&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&quot;I am thinking that I am lazy...&quot; - David Byrne&lt;br /&gt;
&lt;/div&gt;&lt;/blockquote&gt;</description><link>http://seesharpgears.blogspot.com/2009/11/csharpgears-new-class-for-dynamic.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-3984663240952682566</guid><pubDate>Fri, 25 Sep 2009 08:21:00 +0000</pubDate><atom:updated>2009-09-25T10:23:15.184+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">C# free class libraries</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Open Source</category><title>CsharpGears is Free and Open Source Framework</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
I use this opportunity to emphasize the fact that the CsharpGears Framework is absolutely &lt;b&gt;Free&lt;/b&gt; and &lt;b&gt;Open source&lt;/b&gt;, meaning anyone who wants can download the framework and use it for free, or even make changes in the code, but he/she can&#39;t claim he/she invented it.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Recently a reader told me he wanted to use my framework but he was interested in making changes in the source code, and then I noticed that I havent put the full version available for download, so I did that immediately.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And anyone who has some kind of trouble using the CsharpGears framework, may feel free to contact me, I will be happy to help. If anyone has a constructive suggestion or wish for next releases, post it as a suggestion.&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;blockquote&gt;&lt;blockquote&gt;&lt;i&gt;&quot;There is nothing like a dream to create the future&quot; - Victor Hugo&lt;/i&gt;&lt;br /&gt;
&lt;/blockquote&gt;&lt;/blockquote&gt;</description><link>http://seesharpgears.blogspot.com/2009/09/csharpgears-is-free-and-open-source.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-3857747155054013089</guid><pubDate>Fri, 18 Sep 2009 09:25:00 +0000</pubDate><atom:updated>2010-11-01T18:15:37.136+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">C# free class libraries</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">RSS</category><category domain="http://www.blogger.com/atom/ns#">RSS Builder</category><category domain="http://www.blogger.com/atom/ns#">RSS feed</category><title>C# RSS Builder : How to Build Really Simple Syndications</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
RSS has become quite popular recently, and from developer&#39;s point of view, it&#39;s a quite common requirement to implement. So I have decided to make an object-oriented approach and write a few classes that might come in handy. You can see the source code below, it is quite simple and straightforward. One note to those who haven&#39;t read my previous posts: The retrieval from the database is made by another set of classes called DatabaseEntities. These classes allow me to directly bind C# classes with SQL table columns and return lists of business objects instead of DataTables.&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Back to the RSS feed, there are a few things you need to do: first you need RSS items, as by the standard of the RSS XML tags. Then you need to create a logo of the RSS feed. This is optional, but it is a nice way to offer your readers visual connection to your brand. You will also need a Stream object where the feed should be output. It could be any type of stream. For the purposes of this example, I am using a FileStream, but for a real scenario (ASP.NET) you would need to use the Response&#39;s output stream. Take a look at the code, and please tell me if it is REALLY SIMPLE :)&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW7pKTDEpi6tZnCmcrDmpQzrwrCyUA_Ehzq7ICCjwNgIzAyil-_rbPOHOTqVPKOcC19WRBe3sV9bAl-EY1Y-KLBhM122t3J76BFHqCIw_i_yLespDQvejgjm314P0g2jB6nitWs_lBu0YP/s1600-h/ClassDiagram1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW7pKTDEpi6tZnCmcrDmpQzrwrCyUA_Ehzq7ICCjwNgIzAyil-_rbPOHOTqVPKOcC19WRBe3sV9bAl-EY1Y-KLBhM122t3J76BFHqCIw_i_yLespDQvejgjm314P0g2jB6nitWs_lBu0YP/s400/ClassDiagram1.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; RssBuilderLibrary;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.IO;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; DataBaseClassLibrary;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data;
&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; RssBuilderLibraryClient
{
&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Program
{
&lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Main(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;[] args)
{
    &lt;span class=&quot;rem&quot;&gt;/* Retrieve the latest products from the database as RSS items */&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConnectionString = &lt;span class=&quot;str&quot;&gt;&quot;...&quot;&lt;/span&gt;;
    GenericDbEntity&amp;lt;RssItem&amp;gt; dbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; GenericDbEntity&amp;lt;RssItem&amp;gt;(&lt;span class=&quot;str&quot;&gt;&quot;GetLatestProducts&quot;&lt;/span&gt;, 
ConnectionString);
    List&amp;lt;RssItem&amp;gt; latestProducts = (List&amp;lt;RssItem&amp;gt;) dbEntity.Select();
    
    &lt;span class=&quot;rem&quot;&gt;/* Create an image logo in the RSS feed */&lt;/span&gt;
    RssImage imageLogo = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; RssImage();
    imageLogo.Description = &lt;span class=&quot;str&quot;&gt;&quot;This is a description&quot;&lt;/span&gt;;
    imageLogo.Title = &lt;span class=&quot;str&quot;&gt;&quot;This is a title&quot;&lt;/span&gt;;
    imageLogo.Url = &lt;span class=&quot;str&quot;&gt;&quot;http://example.com/image.jpg&quot;&lt;/span&gt;;
    imageLogo.Link = &lt;span class=&quot;str&quot;&gt;&quot;http://mysite.com&quot;&lt;/span&gt;;

    &lt;span class=&quot;rem&quot;&gt;/* Create a stream where the feed should be output - it could be any type of stream */&lt;/span&gt;
    FileStream fileStream = File.Create(&lt;span class=&quot;str&quot;&gt;&quot;rssfeed.xml&quot;&lt;/span&gt;);

    &lt;span class=&quot;rem&quot;&gt;/* Create a RSS channel */&lt;/span&gt;
    RssChannel rss = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; RssChannel(fileStream, imageLogo);

    &lt;span class=&quot;rem&quot;&gt;/* Add all RSS items in the channel */&lt;/span&gt;
    &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt;(IRssItem rssItem &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; latestProducts)
    {
        rss.AddRssItem(rssItem);
    }

    &lt;span class=&quot;rem&quot;&gt;/* Publish the RSS feed to the output stream */&lt;/span&gt;
    rss.Publish();
}
}
}
&lt;/pre&gt;</description><link>http://seesharpgears.blogspot.com/2009/09/c-rss-builder-how-to-build-really.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW7pKTDEpi6tZnCmcrDmpQzrwrCyUA_Ehzq7ICCjwNgIzAyil-_rbPOHOTqVPKOcC19WRBe3sV9bAl-EY1Y-KLBhM122t3J76BFHqCIw_i_yLespDQvejgjm314P0g2jB6nitWs_lBu0YP/s72-c/ClassDiagram1.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-1192844744297123451</guid><pubDate>Tue, 15 Sep 2009 11:30:00 +0000</pubDate><atom:updated>2010-11-01T18:16:53.475+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">C# Gears Framework</category><category domain="http://www.blogger.com/atom/ns#">Database Logger</category><category domain="http://www.blogger.com/atom/ns#">Logger</category><title>C# Logger when Handling Exceptions</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;Having the Logger configured as in the previous post, it is very easy to use it to log exceptions directly. The ILogger interface provides a method called AppendException() which takes a reference of an Exception object, which will log the stack trace, the message and the targetted site of the exception that was thrown. If you are familiar with my previous post, you can use this class from the CsharpGears framework to log your exceptions out-of-the-box. For instance, in ASP.NET web applications, you could use this logger to trace all the exceptions in the global.asax file when handling the event OnApplicationError or anytime an exception occurs and then redirect the user to a custom error page.&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Here is the minimum amount of code to set all that up:&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/* Set up configuration for the logger */&lt;/span&gt;
            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; DbProvider = &lt;span class=&quot;str&quot;&gt;&quot;System.Data.SqlClient&quot;&lt;/span&gt;;
            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConnectionString = &lt;span class=&quot;str&quot;&gt;&quot;...&quot;&lt;/span&gt;;

            &lt;span class=&quot;rem&quot;&gt;/* Create the logger */&lt;/span&gt;
            ILogger Logger = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DbLogger(DbProvider,ConnectionString);
            Configuration.LogLevel = LogLevel.ERROR;

            &lt;span class=&quot;kwrd&quot;&gt;try&lt;/span&gt;
            {
                &lt;span class=&quot;rem&quot;&gt;/* Generate an exception */&lt;/span&gt;
                &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; generates_exception = 1 / 0;
            }
            &lt;span class=&quot;kwrd&quot;&gt;catch&lt;/span&gt; (Exception ex)
            {
                Logger.AppendException(ex);
            }
            &lt;span class=&quot;rem&quot;&gt;/* Retrieve the messages from today */&lt;/span&gt;
            List&amp;lt;LogMessage&amp;gt; TodaysLogContent = Logger.ReadLogByDate(DateTime.Now);

            &lt;span class=&quot;rem&quot;&gt;/* Print the log messages from today */&lt;/span&gt;
            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (LogMessage message &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; TodaysLogContent)
            {
                Console.WriteLine(message.Message + &lt;span class=&quot;str&quot;&gt;&quot; &quot;&lt;/span&gt; + message.UserName + &lt;span class=&quot;str&quot;&gt;&quot; &quot;&lt;/span&gt; + message.Date + &lt;span class=&quot;str&quot;&gt;&quot;\n&quot;&lt;/span&gt;);
            }&lt;/pre&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;h3&gt;Logging Exceptions in ASP.NET websites&lt;/h3&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Application_Error(&lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
            {
                Exception ex = Server.GetLastError();
                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; DbProvider = &lt;span class=&quot;str&quot;&gt;&quot;System.Data.SqlClient&quot;&lt;/span&gt;;
                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConnectionString = &lt;span class=&quot;str&quot;&gt;&quot;...&quot;&lt;/span&gt;;

                &lt;span class=&quot;rem&quot;&gt;/* Create the logger */&lt;/span&gt;
                ILogger Logger = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DbLogger(DbProvider, ConnectionString);
                Configuration.LogLevel = LogLevel.ERROR;
                Logger.AppendException(ex);
                &lt;span class=&quot;rem&quot;&gt;// Clear the error and maybe redirect to some other page...&lt;/span&gt;
                Server.ClearError();
            }&lt;/pre&gt;&lt;br /&gt;
You can see that all you need is a few lines of C# code and an object-oriented approach to your log messages is ready to be used. I really find it useful, would appreciate to tell me what do you think about it.</description><link>http://seesharpgears.blogspot.com/2009/09/c-logger-when-handling-exceptions.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-4333176484970528336</guid><pubDate>Thu, 10 Sep 2009 17:50:00 +0000</pubDate><atom:updated>2010-11-16T08:13:33.580+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">C# Gears Framework</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">Database Logger</category><category domain="http://www.blogger.com/atom/ns#">Log4Net</category><category domain="http://www.blogger.com/atom/ns#">Logger</category><title>Creating C# Logger with CsharpGears</title><description>&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The Need of Logger for C#&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Loggers come in handy when one wishes to trace the execution of his program. These pieces of code make life much easier when it comes to maintaining the application code error free. That is because with logging capabilities, the developer is able to track every time an unusual event occurs. Then it will be easy to determine where the code needs more attention, whether it includes refactoring, bugs or something else.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;There are loggers for C#, they are not something new. But what they often lack, is known as ease-of-use. Here could fall Log4Net and other classes that could be found accross the Web. Often, developer needs a simple logger, some code that will get the job done when an exception is thrown.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Therefore I have decided to write &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;flexible C# classes that will still be extremely simple to use, flexible by design, and will give the developer control of the log level.(Log levels are an important aspect of the loggers, as they give the power to control which events will enter the log, and which will be left out.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;The Database Logger in C#&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;The Logger classes in the CsharpGears Framework are organized in the following way:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrD8KbCjaskmQzkPmdzrITB9R315rlNUmAOW8EbQ6ZEwHsuKY4vmL0n1VAwGRpo-JlTXiYl-AP8rDo_iAs_zmtTdywgcOL2qXC1kG1A3s8JqGj-5mMqgvP_fqEKfvDEC5plniBvGyrFrug/s1600-h/LoggerDiagram.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrD8KbCjaskmQzkPmdzrITB9R315rlNUmAOW8EbQ6ZEwHsuKY4vmL0n1VAwGRpo-JlTXiYl-AP8rDo_iAs_zmtTdywgcOL2qXC1kG1A3s8JqGj-5mMqgvP_fqEKfvDEC5plniBvGyrFrug/s400/LoggerDiagram.jpg&quot; /&gt;&lt;/a&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;&amp;nbsp;There exists a class named &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;LoggerBase &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;which is abstract and it also implements the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;ILogger &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;interface. From it &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DbLogger &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;class is derived, and that is the main class we are going to use. There are also &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;SqlServerDbLoggerProvider&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; class which configures the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DbLogger &lt;/span&gt;so that it creates the needed tables and stored procedures in the database. These logger classes communicate with &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;LogMessages. &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;There is a generic &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;LogMessage&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;from which other &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;LogMessage&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;s are derived. For each log level, there exists an appropriate message.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;So, let&#39;s show an example of the usage of the the C# logger. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;rem&quot;&gt;/* Set up configuration for the logger */&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; DbProvider = &lt;span class=&quot;str&quot;&gt;&quot;System.Data.SqlClient&quot;&lt;/span&gt;;
            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConnectionString = &lt;span class=&quot;str&quot;&gt;&quot;...&quot;&lt;/span&gt;;

            &lt;span class=&quot;rem&quot;&gt;/* Create the logger */&lt;/span&gt;
            ILogger Logger = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DbLogger(DbProvider,ConnectionString);
            Configuration.LogLevel = LogLevel.ERROR;
            &lt;span class=&quot;rem&quot;&gt;/* Create log messages */&lt;/span&gt;
            ILogMessage Message = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; LogMessage(&lt;span class=&quot;str&quot;&gt;&quot;Message Content: Error&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;SYSTEM&quot;&lt;/span&gt;,
LogLevel.INFO);
            ILogMessage InfoMessage = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; InfoLogMessage(&lt;span class=&quot;str&quot;&gt;&quot;Info log message&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;SYSTEM&quot;&lt;/span&gt;);
            ILogMessage ErrorMessage = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ErrorLogMessage(&lt;span class=&quot;str&quot;&gt;&quot;Fatal error&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;SYSTEM&quot;&lt;/span&gt;);
            ILogMessage AllMessage = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AllLogMessage(&lt;span class=&quot;str&quot;&gt;&quot;All log message&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;SYSTEM&quot;&lt;/span&gt;);

            &lt;span class=&quot;rem&quot;&gt;/* Append the messages */&lt;/span&gt;
            Logger.Append(Message);
            Logger.Append(InfoMessage);
            Logger.Append(ErrorMessage);
            Logger.Append(AllMessage);

            &lt;span class=&quot;rem&quot;&gt;/* Retrieve all messages from the log */&lt;/span&gt;
            List&amp;lt;LogMessage&amp;gt; LogContent = Logger.ReadLog();

            &lt;span class=&quot;rem&quot;&gt;/* Retrieve the messages from today */&lt;/span&gt;
            List&amp;lt;LogMessage&amp;gt; TodaysLogContent = Logger.ReadLogByDate(DateTime.Now);

            &lt;span class=&quot;rem&quot;&gt;/* Print the log messages from today */&lt;/span&gt;
            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (LogMessage message &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; TodaysLogContent) 
            {
                Console.WriteLine(message.Message + &lt;span class=&quot;str&quot;&gt;&quot; &quot;&lt;/span&gt; + message.UserName + &lt;span class=&quot;str&quot;&gt;&quot; &quot;&lt;/span&gt;
+ message.Date + &lt;span class=&quot;str&quot;&gt;&quot;\n&quot;&lt;/span&gt;);
            }&lt;/pre&gt;As you can see, you only need to configure the logger for the database provider and the connection string - and you are ready to go. When you want to append a message, you only need to create the appropriate message object - you can either use the interface notation, or create the message type directly, by creating a log message of the specific type. Then you need to invoke the Append() method. For retrieval of the messages from the logger, you need to invoke the method ReadLog(), or you can read the messages from today. (In the future version, I will add an opportunity to read according to the log level). And then, you will get a generic C# list of Log messages. In case you were wondering, this utilizes the DatabaseEntity classes, discussed in my previous post about &lt;b&gt;&lt;a href=&quot;http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-database-access.html&quot;&gt;database access&lt;/a&gt;&lt;/b&gt; with the CsharpGears framework. &lt;br /&gt;
If you have any questions about using this logger, feel free to ask. As you can see, it is very simple to use, and it abstracts most of the annoying things when developing logger classes in C#.</description><link>http://seesharpgears.blogspot.com/2009/09/creating-c-logger-with-csharpgears.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrD8KbCjaskmQzkPmdzrITB9R315rlNUmAOW8EbQ6ZEwHsuKY4vmL0n1VAwGRpo-JlTXiYl-AP8rDo_iAs_zmtTdywgcOL2qXC1kG1A3s8JqGj-5mMqgvP_fqEKfvDEC5plniBvGyrFrug/s72-c/LoggerDiagram.jpg" height="72" width="72"/><thr:total>8</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-2705911442860874089</guid><pubDate>Mon, 31 Aug 2009 16:19:00 +0000</pubDate><atom:updated>2010-11-01T18:18:48.397+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">Business Access Layer (BAL)</category><category domain="http://www.blogger.com/atom/ns#">C# Gears Framework</category><category domain="http://www.blogger.com/atom/ns#">Data Access Layer (DAL)</category><category domain="http://www.blogger.com/atom/ns#">N-Tier Architecture</category><title>Writing Data Access Layer (DAL) and Business Access Layer (BAL) with CsharpGears Framework</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Today I am going to show you how to write Data Access Layer (DAL) and Business Access Layer (BAL) using the CsharpGears Framework.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;One of the most accepted approaches of the today&#39;s application architecture is the &lt;b&gt;3-tier architecture, &lt;/b&gt;or it&#39;s general version &lt;b&gt;n-tier architecture.&lt;/b&gt; The idea is to separate the logic of the application in separate layers, each of which will be able to communicate in a standardized way with another layer. Most often&lt;/span&gt;,&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt; the tier that is responsible for displaying the data is called the &lt;b&gt;presentation layer, &lt;/b&gt;which is capable of invoking the layer that holds all the business logic - namely the &lt;b&gt;business layer. &lt;/b&gt;The business layer, however can either be invoked by the presentation layer and return the results of the execution to it. In certain situations, the business layer will need to access some amount of data in order to perform all the calculations. In that case, the business layer invokes the third layer - &lt;b&gt;data layer. &lt;/b&gt;The data layer is responsible for retrieving the sets of data from some source - be it a database or xml file or web service - it can be literally anything.&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Benefits of the three-tier architecture&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt; Having the application separated in separate tiers (&lt;i&gt;note: tier is synonym for layer&lt;/i&gt;) , brings a lot of advantages, among which are:&lt;/span&gt;&lt;/div&gt;&lt;ul style=&quot;text-align: justify;&quot;&gt;&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;The application is divided in pieces that whose independence is brought to maximum, meaning that people can simultenously work on different layer, leading to cutting the development costs in both aspects of time and money.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Transparency. Each layer brings transparency for the other layers - this means that each layer minds it&#39;s own business, and when it needs help, it simply invokes other layers to help out. The good thing is, nobody interferes in the lives of the others. Moreover, the transparency brings flexibility, such as - the business layer does not care where the data layer gets the data from, its only concern is to get data. The presentation layer does not know nor cares who the data layer is, but it also does not know the details of what the business rules are; instead, the presentation layer only cares to display the results properly so that the end user sees what she needs to see.&amp;nbsp;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;What is the Data Access Layer (DAL)?&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Well, I have mentioned the data layer is the layer that cares about the data, but it might be essentially observed as the Data Storage Layer, with or without capabilities to format the data. The raw data retrieval is usually accomplished by means of using SQL stored procedures, SQL ad-hoc queries, XPath expressions etc. But the thing is, the retrieved data is not always well formatted to align with the benefits of the Object-oriented Programming. In the&amp;nbsp; case of SQL, (the more common I guess), although the data is retrieved as tables, sometimes it is not sufficient. A developer would still need to map that data to objects in the application. Having all this considered, one can define &lt;b&gt;DAL&lt;/b&gt; as the part of the Data Layer that cares for mapping the retrieved rows into business classes (in C#, for instance). Please note that even if the DAL is often written in .NET, it still belongs to the Data Layer, do &lt;i&gt;not&lt;/i&gt; directly assume that the Database represents the whole Data Layer.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;What is Business Access Layer (BAL)?&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;BAL can be observed as an encapsulation of the business logic so that it keeps the transparency to the presentation layer. The part of the business layer that is responsible for invoking the business layer from upper layers - namely the presentation layer is called &lt;b&gt;Business Access Layer.&lt;/b&gt; The BAL always returns objects to the presentation layer that it finds them suitable for displaying. BAL represents the encapsulation of the business layer.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Standardizing the Communication between Layers: Common Objects&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Wouldn&#39;t it be nice if all the tiers communicated in the same fashion ? Of course, the more standardized the communication, the less effort to develop the application, because of the subtle error prevention the standardized communication. Even in practice, people have come to the conclusion that they must have a convention so that they can share ideas and thoughts: that is how protocols were invented. So the main idea here is to write a set of C# classes which will define the communication core between the layers. Those classes will contain no logic inside them, they will be more like OO placeholders for the data. Taking this approach, it becomes obvious that the only way the presentation layer invokes the business layer with some parameters is to construct common objects, fill them with data and send them to the business layer. The business layer, based on what kind of object received, decides to change it, return it, or invoke the data layer. The communication between the data layer and the business layer is also within the common objects domain - that is, the business tier must construct common objects that both the business tier and the data tier understand and send them to it. Once the data layer gets the common objects as parameters, it talks to the persistant medium and returns - a set of common objects to the business layer. The DAL should be well written to handle this transformation from raw data to sets of common objects. The BAL also will return as a result a set of common objects. With this approach in mind, it becomes very easy to develop applications because the code will contain less errors, it maintains its extensibility, new developers could jump in to the project with less effort etc.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Implementing DAL and BAL with CsharpGears Framework&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; font-size: small;&quot;&gt;Have you been following me up to now ? So far, so good. Now lets see how will everything that we said work in practice:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbJ1jpV89e-DaQUvsMiXpeAFXhj65EsSdInAqnZqH3OovHaQe4qK3lOd-eTFm4OK1swoYnXQHVZlGSY3vfzRH_98mCFjk3RE6hlfhOYFNKRylvDfeYTp50tM4ecH8OD185ZlbdotoV9J-z/s1600-h/ClassDiagram.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbJ1jpV89e-DaQUvsMiXpeAFXhj65EsSdInAqnZqH3OovHaQe4qK3lOd-eTFm4OK1swoYnXQHVZlGSY3vfzRH_98mCFjk3RE6hlfhOYFNKRylvDfeYTp50tM4ecH8OD185ZlbdotoV9J-z/s320/ClassDiagram.jpg&quot;  /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;b&gt; &lt;/b&gt;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt; &lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; DevGears.DataBase;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; DataLayer.Properties;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Configuration;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; DataLayer
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; DataLayerBase
    {
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; IDataBase dbEntity;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; connectionString;

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; IDataBase DbEntity
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; dbEntity; }
            set { dbEntity = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ConnectionString
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; connectionString; }
            set { connectionString = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; DataLayerBase() 
        {
            connectionString = Settings.Default.connectionString;        
        }

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; IDataBase CreateDbEntity(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; StoredProcedure) 
        {
            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DataBaseEntity(StoredProcedure, connectionString);
        }

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; AddParameters();
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Execute();

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; AddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value, DbType Type)
        {
            dbEntity.AddCommandParameter(Name, Value, Type);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; IntAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Int32);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; StringAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.String);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; BoolAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Boolean);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; DecimalAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Decimal);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; DoubleAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Double);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; DateTimeAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.DateTime);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; DateAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Date);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ByteAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Byte);
        }
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; LongAddCommandParameter(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name, &lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; Value)
        {
            AddCommandParameter(Name, Value, DbType.Int64);
        }

    }
}&lt;/pre&gt;&lt;br /&gt;
In order to maintain the flexibility of changing the names of the stored procedures I will invoke, I decide to keep them as enum:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; DataLayer
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;enum&lt;/span&gt; StoredProcedure
    {
        CountrySelectAll, 
        LeagueSelectByCountry,
        TeamAllSelect,
        MatchInsert
 &lt;span class=&quot;rem&quot;&gt;//...&lt;/span&gt;
    }
}
&lt;/pre&gt;&lt;br /&gt;
The &lt;b&gt;Data layer&lt;/b&gt; will be constituted of an abstract base class named &lt;b&gt;DataLayerBase&lt;/b&gt; and in it there will be a private element that implements the IDatabase interface from CsharpGears.Database. All database entity objects (discussed earlier) implement that interface. There are also wrapper methods over the methods for adding parameters in the database entity objects. The method Execute() is abstract, meaning all classes that will inherit from this class will also have to provide implementation of it. The method AddParameters() is used to hold all the parametrization of the call to the database. Lets now see how the inherited class would look like:&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; CommonObjects;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; DevGears.DataBase;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; DataLayer
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; TeamAllSelect : DataLayerBase
    {
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; List&amp;lt;Team&amp;gt; resultSet;

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; List&amp;lt;Team&amp;gt; ResultSet
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; resultSet; }
            set { resultSet = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; AddParameters()
        {
            &lt;span class=&quot;kwrd&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; NotImplementedException();
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Execute()
        {
            DbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; GenericDbEntity&amp;lt;Team&amp;gt;(StoredProcedure.TeamAllSelect.ToString(),
                                                    ConnectionString);
            resultSet = (List&amp;lt;Team&amp;gt;)DbEntity.Select();
        }
    }
}
&lt;/pre&gt;Since we don&#39;t need to add parameters to this stored procedure, we decide not to implement the AddParameters() method and leave it like it is. The CommonObject in our case, is the Team class:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; CommonObjects
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Team
    {
        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Private Members
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; teamId;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; name;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; presentationName;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; logoUrl;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; city;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; coordinates;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; leagueId;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; stadiumId;
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Private Members

        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Properties
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; StadiumId
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; stadiumId; }
            set { stadiumId = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; LeagueId
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; leagueId; }
            set { leagueId = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Coordinates
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; coordinates; }
            set { coordinates = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; City
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; city; }
            set { city = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; LogoUrl
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; logoUrl; }
            set { logoUrl = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; PresentationName
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; presentationName; }
            set { presentationName = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Name
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; name; }
            set { name = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; TeamId
        {
          get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; teamId; }
          set { teamId = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Properties
    }
}&lt;/pre&gt;Now, going upper to the business tier, we have the following BAL object:&lt;br /&gt;
&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuSX4wVXhG4W4JioZG1_BEsYTx0ki-UyiHYGmqeJnpbHF5RWngaDS_wtmAzN6FyA_aGgJD5Le-PXkql4se9Q6kaHMsiCeIi_OHcE4mng4M2I1nRjxk2l9Wjh2TIIk5uS5NMy7S51-sMvEc/s1600-h/ClassDiagramBL.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuSX4wVXhG4W4JioZG1_BEsYTx0ki-UyiHYGmqeJnpbHF5RWngaDS_wtmAzN6FyA_aGgJD5Le-PXkql4se9Q6kaHMsiCeIi_OHcE4mng4M2I1nRjxk2l9Wjh2TIIk5uS5NMy7S51-sMvEc/s320/ClassDiagramBL.jpg&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; BusinessLayer
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; BusinessLayerBase
    {
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Invoke();
    }
}&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; CommonObjects;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; DataLayer;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; BusinessLayer
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; TeamAllSelectProcess : BusinessLayerBase
    {
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; List&amp;lt;Team&amp;gt; resultSet;

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; List&amp;lt;Team&amp;gt; ResultSet
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; resultSet; }
            set { resultSet = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Invoke()
        {
            TeamAllSelect teamAllSelect = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; TeamAllSelect();
            teamAllSelect.Execute();
            resultSet = teamAllSelect.ResultSet;
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
Now, the cherry in the cream. In the presentation layer, we have an user control containing dropdown list that we want populated:&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.UI;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.UI.WebControls;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; CommonObjects;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; BusinessLayer;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Drawing;

&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; FiksApp.UserControls
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;partial&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; HeadToHead : System.Web.UI.UserControl
    {
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Page_Load(&lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!Page.IsPostBack)
            {
                TeamAllSelectProcess teamAllSelectProcess = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; TeamAllSelectProcess();
                teamAllSelectProcess.Invoke();
                ddlTeam1.DataSource = teamAllSelectProcess.ResultSet;
                ddlTeam1.DataBind();
            }
        }
    }
}&lt;/pre&gt;&lt;br /&gt;
That is all practically. I have guided you in a thorough process of designing the DAL and BAL of web application using the benefits of the CsharpGearsFramework. It would be nice to hear your comments, as they encourage me to further extend the framework and go on writing more posts.</description><link>http://seesharpgears.blogspot.com/2009/08/writing-data-access-layer-dal-and.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbJ1jpV89e-DaQUvsMiXpeAFXhj65EsSdInAqnZqH3OovHaQe4qK3lOd-eTFm4OK1swoYnXQHVZlGSY3vfzRH_98mCFjk3RE6hlfhOYFNKRylvDfeYTp50tM4ecH8OD185ZlbdotoV9J-z/s72-c/ClassDiagram.jpg" height="72" width="72"/><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-3952346934289428447</guid><pubDate>Fri, 28 Aug 2009 15:33:00 +0000</pubDate><atom:updated>2010-11-01T18:19:31.116+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">Business Access Layer (BAL)</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Data Access Layer (DAL)</category><category domain="http://www.blogger.com/atom/ns#">N-Tier Architecture</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><title>CsharpGears Framework : Object-Relational Mapping</title><description>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Reasons for Object-Relational Mapping&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;Since the rapid development of the relational databases and the acceptance of the Object-Oriented Programming model, a new need rose: to quickly and correctly map the persistance medium model (namely, the SQL tables) to the business objects in some high level programming language&lt;b&gt; &lt;/b&gt;(C# for instance). Developers noticed that they invest significant amount of time writing the Data Access Layer (DAL) when starting off a new project, so they started looking for ways to decrease that time and effort. As time went by, several companies started producing software to efficiently map the SQL tables into business classes. Today, numerous of them are fairly famous, such as the NHibernate, SubSonic, Microsoft&#39;s Entity Framework, LINQ, etc. You can find more detailed list of ORM software on wikipedia.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Benefits of the ORM&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;The main benefits from using ORM software can be distinguished in the following categories:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Far less time spent on writing the DAL&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Less errors on the low level of your application&lt;/span&gt;&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Robustness and easy maintenance, cleaner code in the Business Access Layer (BAL&lt;/span&gt;)&lt;/i&gt;&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Object-Relational Mapping (ORM) with C# Gears Framework&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;I have thought of a way to offer ORM functionalities from my framework, and I think it is quite efficient, although it does not &lt;i&gt;yet&lt;/i&gt; offer all the bells and whistles of other frameworks that exist today. For now 5 projects are built on top of the framework, and its ORM capabilities have proven to be very easy to deploy, flexible and easy to use. Basically, the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;GenericDbEntity&lt;/span&gt; &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;is able to map the columns from the SQL datareader to the columns of the C# class and as a result of the query execution, it returns a generic list with such business objects. The query result data is avaliable for business logic imm&lt;/span&gt;ediately after its fetch from the database. By that I have measured I spend in average 60 - 70 % less time on development of the DAL. However, this number will vary from project to project, and as I use it on more projects I will be able to give more accurate percentage of the time saving. The ORM part of the CsharpGears Framework utilizes the generics and code reuse capabilities of C#, which are one of the biggest strengths of the OOP.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Example: Using the ORM capabilities within the CsharpGears Framework&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;Lets consider the following situation. Imagine you are writing ASP.NET application for an e-shop. You have SQL table in the database that holds the products which looks like this:&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVIo5xo5RCz4fDWg9T-qe-wcogg2aoPq4m1wHhBKUHwoFwTZF4dtUCJamXo5tdwPiZaTjmN8SQ3ibnFbO5B6akf_3o4E2umk5PAxB9n1KRnIa2g5D5KklppkrYW56z2vgCcFgvszCqWVX7/s1600-h/Products+table.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVIo5xo5RCz4fDWg9T-qe-wcogg2aoPq4m1wHhBKUHwoFwTZF4dtUCJamXo5tdwPiZaTjmN8SQ3ibnFbO5B6akf_3o4E2umk5PAxB9n1KRnIa2g5D5KklppkrYW56z2vgCcFgvszCqWVX7/s400/Products+table.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;As you can see, there is nothing unusual with this table. Let&#39;s say that we want to write a procedure that retrieves all products in given category:&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;CREATE&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;PROCEDURE&lt;/span&gt; ProductsInCategory_Select
(
 @CategoryId BIGINT
)
&lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt;
&lt;span class=&quot;kwrd&quot;&gt;BEGIN&lt;/span&gt;    
    &lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt;
            ProductID
            &lt;span class=&quot;kwrd&quot;&gt;SUBSTRING&lt;/span&gt;(Description,1,15) + &lt;span class=&quot;str&quot;&gt;&#39;...&#39;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; Description,
            ImageUrl,
            Price,
            &lt;span class=&quot;kwrd&quot;&gt;Date&lt;/span&gt;,
            Title,
            Product.CategoryID,
            Name &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; categoryName,
            ThumbnailUrl &lt;span class=&quot;kwrd&quot;&gt;AS&lt;/span&gt; thumbnailUrl
    &lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt;
            Product &lt;span class=&quot;kwrd&quot;&gt;INNER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; Category &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; Product.CategoryID = Category.CategoryID
    
    &lt;span class=&quot;kwrd&quot;&gt;WHERE&lt;/span&gt;
            Product.CategoryID = @CategoryID
END&lt;/pre&gt;&lt;br /&gt;
... &lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;and lets assume that we have the following business classes:&lt;/span&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Category
    {
        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Attributes
        &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; categoryId;
        &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; categoryName;
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Attributes

        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Constructors
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Category() { }
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Constructors

        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Properties
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; CategoryName
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; categoryName; }
            set { categoryName = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; CategoryId
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; categoryId; }
            set { categoryId = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Properties
    }&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Product
    {
        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Attributes
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; id;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; title;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; description;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;double&lt;/span&gt; price;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; DateTime date;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; imageUrl;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; thumbnailUrl;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; Category category;
        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; quantity;
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Attributes


        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Constructors
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Product()
        {
            category = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Category();
        }
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Constructors

        
        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Properties

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; CategoryId
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; category.CategoryId; }
            set { category.CategoryId = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; CategoryName
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; category.CategoryName; }
            set { category.CategoryName = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ThumbnailUrl
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; thumbnailUrl; }
            set { thumbnailUrl = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ImageUrl
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; imageUrl; }
            set { imageUrl = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; DateTime Date
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; date; }
            set { date = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;double&lt;/span&gt; Price
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; price; }
            set { price = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Description
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; description; }
            set { description = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }


        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Title
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; title; }
            set { title = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; Id
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; id; }
            set { id = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; Category Category
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; category; }
            set { category = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }

        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; Quantity
        {
            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; quantity; }
            set { quantity = &lt;span class=&quot;kwrd&quot;&gt;value&lt;/span&gt;; }
        }
        
        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt; Properties
    }&lt;/pre&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Then, in order to retrieve the products as a generic list, I would just use the following code:&lt;/div&gt;&lt;pre class=&quot;csharpcode&quot;&gt;GenericDbEntity&amp;lt;Product&amp;gt; dbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; GenericDbEntity&amp;lt;Product&amp;gt;(&lt;span class=&quot;str&quot;&gt;&quot;ProductsInCategory_Select&quot;&lt;/span&gt;, ConnectionString);
            dbEntity.IntAddCommandParameter(&lt;span class=&quot;str&quot;&gt;&quot;@CategoryId&quot;&lt;/span&gt;, 1);
            List&amp;lt;Product&amp;gt; resultSet = (List&amp;lt;Product&amp;gt;)dbEntity.Select();&lt;/pre&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;And that is practically, it. I am immediately ready to work with my business objects (Products in this case). As you can observe, the CsharpGears easily handles class composition&lt;/span&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt; and once again proves flexibility. This ease of use comes from the fact that the framework directly maps the SQL columns into the properties of the C# class - no static mapping is requiered. Hence, by writing a simple property I could handle composition of objects without any unnecesary code.&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;Summary Note&lt;/span&gt;&lt;/b&gt; &lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;As stated in the example above, the ORM software offers time saving techniques when writing software applications and makes the software more flexible and robust. A number of good tools already exist, but the free CsharpGears Framework also offers ORM functionalities efficiently. This framework does not intend to compete with LINQ or Entity Framework, but can come in handy when someone is still unfamiliar with them, or just wants a simple way to access data from the database and work with it in the application as business objects. The CsharpGears Framework so far has been reported to cut time spent on developing DAL up to 70 % and I hope in future I will be able to give more accurate percentages.&lt;/span&gt;&lt;/div&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-object-relational.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVIo5xo5RCz4fDWg9T-qe-wcogg2aoPq4m1wHhBKUHwoFwTZF4dtUCJamXo5tdwPiZaTjmN8SQ3ibnFbO5B6akf_3o4E2umk5PAxB9n1KRnIa2g5D5KklppkrYW56z2vgCcFgvszCqWVX7/s72-c/Products+table.jpg" height="72" width="72"/><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-4306867764600920992</guid><pubDate>Fri, 28 Aug 2009 11:33:00 +0000</pubDate><atom:updated>2010-11-01T18:21:06.420+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">C# Gears Framework</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><category domain="http://www.blogger.com/atom/ns#">MySQL DataProvider</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><title>CsharpGears Framework : Using Different SQL Providers</title><description>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;Hello, I am about to present you how easily can you connect different &lt;b&gt;types of databases &lt;/b&gt;with the C# Gears Framework. First of all, note that the IDatabase interface implementators do not care to what type of database they are connected to, they only care about the SQL query they need to execute. For example, here is how would you use C# Gears Framework in order to connect &lt;b&gt;MySQL Database &lt;/b&gt;with .NET:&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Connecting MySQL with C#&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;Step 1:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;Download and install the MySQL provider for .NET.&lt;/b&gt; &lt;/span&gt;&lt;/span&gt;Simply go to &lt;a href=&quot;http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-6.0.4.zip/from/pick&quot;&gt;MySQL&#39;s download site&lt;/a&gt; and create an account if you already don&#39;t have one. The installation is pretty straightforward - there is a MSI installer.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;b&gt;Step 2:Add the MySQL.data.dll to your project. &lt;/b&gt;Ordinarily create new project in Visual Studio, go to &lt;b&gt;References, &lt;/b&gt;right click on it and choose &lt;b&gt;Add Reference. &lt;/b&gt;Then navigate to the path where the installation of the MySQL provider resides, and choose the mentioned dll.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;b&gt;Step 3: Start using the MySQL data provider. &lt;/b&gt;Now I will paste the whole code from my &lt;b&gt;Default.aspx.cs&lt;/b&gt; file:&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.UI;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.UI.WebControls;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; MySql.Data.MySqlClient;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; CsharpGears.DataBase;
&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data;
&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; MySQLTest
{
    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;partial&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; _Default : System.Web.UI.Page
    {
        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Page_Load(&lt;span class=&quot;kwrd&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
        {

            DataBaseEntity dbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DataBaseEntity(&lt;span class=&quot;str&quot;&gt;&quot;Select * FROM `product`&quot;&lt;/span&gt;,
CommandType.Text, 
&lt;span class=&quot;str&quot;&gt;&quot;server=localhost;database=testdb;uid=root;password=&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;MySql.Data.MySqlClient&quot;&lt;/span&gt;);
            DataTable dt = (DataTable)dbEntity.Select();
            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (DataRow dr &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; dt.Rows) 
            {
                Response.Write(dr[&lt;span class=&quot;str&quot;&gt;&quot;ID&quot;&lt;/span&gt;].ToString() + &lt;span class=&quot;str&quot;&gt;&quot;: &quot;&lt;/span&gt; + dr[&lt;span class=&quot;str&quot;&gt;&quot;Description&quot;&lt;/span&gt;].ToString() + 
&lt;span class=&quot;str&quot;&gt;&quot; - &quot;&lt;/span&gt; + dr[&lt;span class=&quot;str&quot;&gt;&quot;Date&quot;&lt;/span&gt;].ToString());
            }
        }
    }
}
&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;And that is it! You see, there is no difference in the usage of the DataBaseEntity object, you only use a different constructor which takes the connection string and the data provider as its parameters. The rest of the parameters are explained in the previous posts - it&#39;s just an ordinary ad-hoc SQL query call. I hope that the C# Gears Framework is helpful to you, as it saves a lot of time that would be otherwise spent on writing tedious code.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;One last note before I go, this article assumes that you already know how to create MySQL database and it is not intended to be MySQL.NET tutorial. The author is sure you can find plenty of sources throughout the Internet on how to create MySQL database. Personally, i prefer the phpMyAdmin application for managing MySQL databases. PhpMyAdmin comes with the installation of &lt;b&gt;WAMP&lt;/b&gt; (Windows-Apache-MySQL-PHP). You should also keep in mind that you need to start Apache in order to access the database from ASP.NET &lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-using-different.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-2014681178223789286</guid><pubDate>Thu, 27 Aug 2009 09:37:00 +0000</pubDate><atom:updated>2010-11-01T18:22:31.115+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Decorator Design Pattern</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><category domain="http://www.blogger.com/atom/ns#">output parameters</category><category domain="http://www.blogger.com/atom/ns#">SQL</category><category domain="http://www.blogger.com/atom/ns#">stored procedures</category><title>CsharpGears Framework : Database Access: Output Parameters</title><description>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;Sometimes it is required that the stored procedures have output parameters. The CsharpGears can handle that too. There is another class in the Database namespace, that specializes working with output parameters. It is called &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DataBaseOutputEnabledEntity&lt;/span&gt; . Here is an example on how it&#39;s used:&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;DataBaseEntity dbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DataBaseEntity(&lt;span class=&quot;str&quot;&gt;&quot;GetProductByID&quot;&lt;/span&gt;);
DataBaseOutputEnabledEntity outputEnabledDbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DataBaseOutputEnabledEntity(dbEntity);
            outputEnabledDbEntity.AddCommandParameter(&lt;span class=&quot;str&quot;&gt;&quot;@NumberOfProducts&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;, DbType.Int32);
            DataTable results = (DataTable)outputEnabledDbEntity.Select();
            &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; outputParamValue = (&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;)outputEnabledDbEntity.GetOuputParameterValue(&lt;span class=&quot;str&quot;&gt;&quot;@NumberOfProducts&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;As you can see, as usual, I first create &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DataBaseEntity &lt;/span&gt;object and bind it with the stored procedure &quot;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;GetProducts&lt;/span&gt;&quot; (which is not shown here, but we assume it resides on SQL server). Lets assume that that stored procedure has one output parameter named &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;@NumberOfProducts &lt;/span&gt;and it stores the number of products returned by the stored procedure. (This may be trivial example, but its nature is purely for demonstration purposes). Then I create a &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DataBaseOutputEnabledEntity &lt;/span&gt;object and bind it with the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DataBaseEntity &lt;/span&gt;I have previously created. When using the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;AddCommandParameter()&lt;/span&gt; method from the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DataBaseOutputEnabledEntity&lt;/span&gt; class, it basically adds &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DbParameter&lt;/span&gt;-s with the direction set to Output. In order to invoke the stored procedure, the only thing that needs to be called is the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;Select()&lt;/span&gt; method. If you are wondering how are you going to read the value from the output parameter after the query execution, here is the solution: you only need to invoke the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;GetOutputParameterValue()&lt;/span&gt; with the name of the parameter. It is that easy to invoke stored procedures with output parameters using the CsharpGears Framework. If you have not downloaded it that yet, I encourage you to do it &lt;a href=&quot;http://vladoa.bravehost.com/Csharpgears-Database.dll&quot;&gt;here&lt;/a&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Little note for the software designers here: &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DatabaseOutputEnabledEntity &lt;/span&gt;basically follows the &lt;b&gt;Decorator Design Pattern&lt;/b&gt; as its constructor takes an &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;IDatabase &lt;/span&gt;object. I have made this decision so that it offers more flexibility and extensibility. In this case, that proved to be a good decision. But as I learn more and more about design patterns, it becomes clear that they should be the applied as a refactoring method, because when you are trying to develop a solution to a particular problem, you need to focus on the problem, not on some UML diagrams for patterns. In future I will write more about design patterns. That&#39;s it, for now.&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-database-access_27.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-4312506271327819897</guid><pubDate>Wed, 26 Aug 2009 17:59:00 +0000</pubDate><atom:updated>2009-08-30T05:32:44.354+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">CommitableTransaction</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Database Access</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><category domain="http://www.blogger.com/atom/ns#">SQL Transactions</category><title>CsharpGears Framework : Database Access- SQL Transactions</title><description>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once you understood the basic ways of utilizing the CsharpGears Framework Database Access, now I will show you how to treat the SQL queries as transactions. Please note that in order to use the SQL transactions entities, you first need to add a reference to the System.Transactions namespace. After that, using the transaction database entity is very easy and similar to the previous examples:&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;TransactionDbEntity&amp;lt;LogMessage&amp;gt; tDbEntity = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; TransactionDbEntity&amp;lt;LogMessage&amp;gt; (&lt;span class=&quot;str&quot;&gt;&quot;LogRead&quot;&lt;/span&gt;,ConnectionString);
List&amp;lt;LogMessage&amp;gt; list = (List&amp;lt;LogMessage&amp;gt;)(tDbEntity.Select());&lt;/pre&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Here I consider retrieving the log from a database as list of LogMessage instances. The LogMessage class basically contains ID, Sender, Description and Date properties that need to be bound.This Database entity essentially creates CommitableTransaction object inside and commits it if the query passes successfully, otherwise performs rollback. But once again, my point was to show you how easy is to treat queries as transactions. Nevertheless, you can still write the transaction handling in the storet procedure&#39;s body, but just in case you have already written hundreds of procedures without database transactions, this class might come in handy.&lt;/div&gt;&lt;/div&gt;&lt;script type=&quot;text/javascript&quot;&gt;&lt;!--
google_ad_client = &quot;pub-9860242120065693&quot;;
/* 728x15, created 8/29/09 */
google_ad_slot = &quot;7970690210&quot;;
google_ad_width = 728;
google_ad_height = 15;
//--&gt;
&lt;/script&gt;&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;
src=&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;&gt;
&lt;/script&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-database-access_26.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-9106639515104067463</guid><pubDate>Wed, 26 Aug 2009 00:48:00 +0000</pubDate><atom:updated>2010-11-01T18:23:16.764+01:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">bind SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">Database Access</category><category domain="http://www.blogger.com/atom/ns#">Direct mapping from SQL to C#</category><category domain="http://www.blogger.com/atom/ns#">easy db access</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><category domain="http://www.blogger.com/atom/ns#">SQL</category><title>CsharpGears Framework : Database Access</title><description>&lt;div style=&quot;font-family: trebuchet ms; text-align: justify;&quot;&gt;You have worked with databases, right ? Has it happened to you, to figure it out that it would be great if you could somehow magically map your SQL tables in neat C# classes ? Well, it&#39;s not that I am discovering new continents here, but I personally think that the Database Access sublibrary will effectively and easily allow you to map your database tables into C# classes. Among the other benefits, these classes can also come in handy if you wanted to treat some SQL queries as transactions and roll them back in case of error. You can also invoke stored procedures or simply pass ad-hoc queries to the database with just a few lines of code.&lt;br /&gt;
&lt;br /&gt;
But what truely makes this library awesome, is it&#39;s ability to directly return lists of business objects. You don&#39;t even have to explicitely bind the class&#39; properties to the SQL tables (as with Attributes). The Framework only requires that the name of the public property is &lt;span style=&quot;font-weight: bold;&quot;&gt;the same &lt;/span&gt;as the name of the SQL table column. Have I mentioned that the library is absolutely generic ? It can accept any types of objects, as long as they have default constructor (which could be observed as limitation, but it is so simple to write it, that is no big deal). Well, enough introductory notes, let me show you what library can really do.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;DatabaseEntity&lt;/b&gt;&lt;br /&gt;
This is the basic class in this library. It provides the basic functionality such as communicating with the database by executing queries. There are several constructors available which will allow you to choose your connection string to the database, the SQL provider, the type of the query (Stored procedure or ad-hoc query) etc. The DatabaseEntity class provides the four main query types in SQL: Select, Insert, Update, Delete. Please note that the Select query returns &lt;i&gt;object&lt;/i&gt; which is actually DataTable (boxed). You need to cast it to DataTable for the sake of reusability of the code. So here is how it works.&lt;br /&gt;
Say you have the following table named &lt;b&gt;Product&lt;/b&gt;&amp;nbsp; with the following columns in the database:&lt;br /&gt;
ID | Description | Price&lt;br /&gt;
&lt;br /&gt;
Then suppose that I wanted to retrieve all Products from the SQL table Product. I write the following procedure:&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;CREATE PROCEDURE ProductsGetAll_Select
AS
BEGIN
SELECT
      ID,
      Description,
      Price
FROM
      Product
END&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Then back in C#, I need to create DataBaseEntityobject:&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;string ConnectionString = &quot;...&quot;;
string DbProvider = &quot;System.Data.SqlClient&quot;;
DataBaseEntity dbEntity = new DataBaseEntity(&quot;ProductsGetAll_Select&quot;,ConnectionString, DbProvider);

DataTable dtResults = (DataTable)dbEntity.Select();

foreach(DataRow dr in dtResults)
{
Console.Write(dr[&quot;ID&quot;] + &quot; &quot; + dr[&quot;Description] &quot; &quot; + dr[&quot;Price&quot;]);
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;So basically, that is all you need to do in order to retrieve your data from the database. For other types of SQL queries you just need to invoke the appropriate method (namely Update, Insert, Delete).&lt;/div&gt;&lt;br /&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Using the DataBaseEntity class for ad-hoc SQL queries&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;DataBaseEntity dbEntity = new DataBaseEntity(&quot;SELECT * FROM Product&quot;, CommandType.Text, ConnectionString);
DataTable dt = (DataTable)dbEntity.Select();&lt;/pre&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;b&gt;GenericDbEntity&lt;/b&gt;&lt;/div&gt;Well, I have mentioned that this library is able to directly return lists of business objects instead of returning DataTable. This is good simply because you won&#39;t bother to map those nasty data rows into your own objects. So here is how it goes:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;public class Product
{
  private int id;
  private double price;
  private string description;
 
  public Product(){}

  public string Description{ get{return description;} set{description = value;}}
  public double Price{get{return price;} set{price = value;}}
  public int Id {get {return id;} set {id = value;}}
}&lt;/pre&gt;&lt;pre&gt;...&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: large;&quot;&gt;&lt;b&gt;Binding SQL results to C# Objects&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt; 
&lt;/pre&gt;&lt;pre&gt;&lt;/pre&gt;&lt;pre style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;b&gt;SELECT Query to C# objects example&lt;/b&gt; &lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;csharpcode&quot;&gt;GenericDbEntity dbEntity = new GenericDbEntity(&quot;ProductsGetAll_Select&quot;,ConnectionString, DbProvider);
List&amp;lt;Product&amp;gt; listOfProducts = (List&amp;lt;Product&amp;gt;)dbEntity.Select();&lt;/pre&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; font-size: small;&quot;&gt;&lt;b&gt;INSERT Query&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;csharpcode&quot;&gt;GenericDbEntity dbEntity = new GenericDbEntity(&quot;Product_Insert&quot;,ConnectionString, DbProvider);
int newlyInsertedId = Convert.ToInt32(dbEntity.Insert());&lt;/pre&gt;&lt;pre style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;product&gt;
&lt;/product&gt;&lt;/span&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;UPDATE Query&lt;/span&gt;&lt;/b&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre class=&quot;csharpcode&quot;&gt;GenericDbEntity dbEntity = new GenericDbEntity(&quot;Product_Update&quot;,ConnectionString, DbProvider);
dbEntity.Update();&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;/product&gt;&lt;b&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;DELETE Query&lt;/span&gt;&lt;/b&gt;&lt;/b&gt;&lt;/pre&gt;&lt;pre class=&quot;csharpcode&quot;&gt;GenericDbEntity dbEntity = new GenericDbEntity(&quot;Product_Delete&quot;,ConnectionString, DbProvider);
dbEntity.Delete();&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;/span&gt;&lt;/product&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;product&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;b style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;
&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Adding Parameters to Database Entities&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; font-size: small;&quot;&gt;You can easily&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;pass SQL parameters as well. Consider the following example:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;b&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre class=&quot;csharpcode&quot;&gt;dbEntity = new DataBaseEntity(&quot;GetProductByID&quot;);
            dbEntity.IntAddCommandParameter(&quot;@ProductID&quot;, 150);
            DataTable dt = (DataTable)dbEntity.Select();&lt;/pre&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;

&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;Note the method &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;IntAddCommandParameter()&lt;/span&gt; adds new &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DbParameter&lt;/span&gt; to the wrapped SQL command.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;The first argument is the name of the parameter in the stored procedure, and the second is the actual value&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;we want to pass. There is also more generic &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;AddCommandParameter()&lt;/span&gt; method which takes&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;the first two parameters just as the &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;IntAddCommandParameter()&lt;/span&gt;, but it also takes a third parameter of &lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;&quot;&gt;DbType&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;pre&gt;&lt;product&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;to specify the type the database should treat it like.  &lt;/span&gt;&lt;/span&gt;

&lt;/span&gt;&lt;/product&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;That is literally, It. Nothing more is needed, indeed.&lt;br /&gt;
&lt;br /&gt;
Please note that I am aware of various other approaches to this problem, such as the SQL Helper classes, Entity Framework etc, but simplicity this library bears makes it my first choice when it comes to communication with the database.&lt;/div&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework-database-access.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-3956325621579144009</guid><pubDate>Wed, 26 Aug 2009 00:13:00 +0000</pubDate><atom:updated>2009-08-27T10:26:31.321+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">CsharpGears Framework</category><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">E-mail</category><category domain="http://www.blogger.com/atom/ns#">Images</category><category domain="http://www.blogger.com/atom/ns#">Logger</category><category domain="http://www.blogger.com/atom/ns#">RSS</category><category domain="http://www.blogger.com/atom/ns#">URL rewrite</category><title>The CsharpGears Framework</title><description>&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif; text-align: justify;&quot;&gt;I introduce you my development framework: &lt;span style=&quot;font-weight: bold;&quot;&gt;CsharpGears&lt;/span&gt;. It is written in C# and its purpose is to speed up the development process, especially in the fundamental levels. It is meant to make developer&#39;s life easier when it comes to writing code such as accessing databases and mapping SQL tables into business objects ( C# classes ), or also for easy work with images, or other types of services, such as loggers or quickly writing code for RSS publishes, or maybe that tedious code for sending emails...&lt;br /&gt;
I personally find it very time-saving, and I hope that someone else out there will find it useful. To summarize, the CsharpGears Framework currently consists of six sublibraries:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Database access&lt;/li&gt;
&lt;li&gt;Logger activities&lt;/li&gt;
&lt;li&gt;E-mail sending&lt;/li&gt;
&lt;li&gt;Working with images&lt;/li&gt;
&lt;li&gt;RSS builder&lt;/li&gt;
&lt;li&gt;URL rewriting policies&lt;/li&gt;
&lt;/ol&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNOkBksQ2Bcw7-p86q7qsYCKcxgjO9QGNdvjcE9GIe0Eff20rR5drZA1rr9p751KVB9VNve1EQKIZFjUIjNVBtYf9hpsVuRmIUXvV35vK4mNQ8zNxenJLWn3peq9bE5MmRDTN0D6sDeuIb/s1600-h/CsharpGearsArchitecture.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNOkBksQ2Bcw7-p86q7qsYCKcxgjO9QGNdvjcE9GIe0Eff20rR5drZA1rr9p751KVB9VNve1EQKIZFjUIjNVBtYf9hpsVuRmIUXvV35vK4mNQ8zNxenJLWn3peq9bE5MmRDTN0D6sDeuIb/s320/CsharpGearsArchitecture.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;/div&gt;Each component will be covered in details in the following posts. Examples of its usage will also be included. Remember that you are able to download the class libraries for &lt;span style=&quot;font-weight: bold;&quot;&gt;free.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt;&amp;nbsp;Installation of the CsharpGears Framework&lt;/span&gt;&lt;br /&gt;
All you need to do in order to utilize the benefits of my framework is to : (1)download it from the downloads section, (2) add it as reference to any .NET project you would like to use it in.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b&gt;End Note&lt;/b&gt; &lt;br /&gt;
&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;I would also emphasize once again that I would be very happy first if someone else decides to use my framework, but I would be even happier if you provide me with your feedback.&lt;/div&gt;&lt;div style=&quot;font-family: &amp;quot;Trebuchet MS&amp;quot;,sans-serif;&quot;&gt;&lt;/div&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/csharpgears-framework.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNOkBksQ2Bcw7-p86q7qsYCKcxgjO9QGNdvjcE9GIe0Eff20rR5drZA1rr9p751KVB9VNve1EQKIZFjUIjNVBtYf9hpsVuRmIUXvV35vK4mNQ8zNxenJLWn3peq9bE5MmRDTN0D6sDeuIb/s72-c/CsharpGearsArchitecture.jpg" height="72" width="72"/><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-493733235295437780.post-7392314549029550366</guid><pubDate>Tue, 25 Aug 2009 23:44:00 +0000</pubDate><atom:updated>2009-08-28T16:47:53.737+02:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ASP.NET</category><category domain="http://www.blogger.com/atom/ns#">C#</category><category domain="http://www.blogger.com/atom/ns#">comments</category><category domain="http://www.blogger.com/atom/ns#">encourage</category><category domain="http://www.blogger.com/atom/ns#">free code examples. class libraries</category><category domain="http://www.blogger.com/atom/ns#">Object Relational Mapping</category><category domain="http://www.blogger.com/atom/ns#">see sharp</category><title>Free C# libraries and examples</title><description>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: trebuchet ms;&quot;&gt;Hello everybody!&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: trebuchet ms;&quot;&gt;This blog is dedicated to publishing for download some of my class libraries I have written in C#. I hope you will find my classes useful and I sincerely encourage you to send me feedback about your experience. Any suggestions, critics and ideas are welcome. All the code examples and libraries will be absolutely free. OK, so it is time to see sharp...&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;</description><link>http://seesharpgears.blogspot.com/2009/08/free-c-libraries-and-examples.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>6</thr:total></item></channel></rss>