<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>wcode.net &#187; C#</title>
	<atom:link href="http://wcode.net/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://wcode.net</link>
	<description>Article and Personal Blog</description>
	<lastBuildDate>Tue, 24 Nov 2009 10:51:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create Array Parameters in C#</title>
		<link>http://wcode.net/2009/11/create-array-parameters-in-c/</link>
		<comments>http://wcode.net/2009/11/create-array-parameters-in-c/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 15:20:58 +0000</pubDate>
		<dc:creator>Willy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[KNN]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[Nearest Neighbor]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Parameters]]></category>

		<guid isPermaLink="false">http://wcode.net/?p=75</guid>
		<description><![CDATA[Today i have request from &#8216;bad friend&#8217; code name &#8216;mashudi&#8217; to create Nearest Neighbor Class, Artificial Intelegent system that can compute distance from one to other node.
From this project I will share how to create a constructor or maybe you need for method that use array parameters.
Design of implementation in KNN node class will be [...]]]></description>
			<content:encoded><![CDATA[<p>Today i have request from &#8216;bad friend&#8217; code name &#8216;mashudi&#8217; to create Nearest Neighbor Class, Artificial Intelegent system that can compute distance from one to other node.</p>
<p>From this project I will share how to create a constructor or maybe you need for method that use array parameters.</p>
<p>Design of implementation in KNN node class will be like this :</p>
<pre class="brush:csharp">
KNNNode node1 = new KNNNode("Rose", 2.5, 4, 4.2);
KNNNode node2 = new KNNNode("Height", 2.5, 4, 4.2, 4.5, 6.3);
</pre>
<p>So you can add more parameters to that class.</p>
<p><span id="more-75"></span></p>
<p>Here my code in KNNNode class :</p>
<pre class="brush:csharp">

using System.Collections.Generic;

namespace Algorithm.KNN
{
    public class KNNNode
    {
        List<float> val;
        string label;

        public string Label
        {
            get { return label; }
            set { label = value; }
        }

        // 'params float[] val' it will create array parameters
        public KNNNode(string label, params float[] val)
        {
            //set label
            this.label = label;
            //Set actual size of val
            this.val = new List<float>(val.Length); 

            //iterate from first to last argument
            //and fill to list
            foreach (float v in val)
            {
                this.val.Add(v);
            }
        }

        public int Count
        {
            get {
                return val.Count;
            }
        }

        //prevent default constructor inisialization
        private KNNNode()
        { }

        //Direct access to list value
        public float this[int index]
        {
            get { return val[index]; }
            set { val[index] = value; }
        }
    }
}
</pre>
<p>Hope it&#8217;s help<br />
Willy Achmat Fauzi</p>
]]></content:encoded>
			<wfw:commentRss>http://wcode.net/2009/11/create-array-parameters-in-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>C# with MySQL Database</title>
		<link>http://wcode.net/2009/10/csharp-with-mysql-database/</link>
		<comments>http://wcode.net/2009/10/csharp-with-mysql-database/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 16:23:44 +0000</pubDate>
		<dc:creator>Willy</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://wcode.net/?p=71</guid>
		<description><![CDATA[If you want direct connection from C# to MySQL you can use MySQL.Data library from this resource. I&#8217;ve write down my own DataAccess class to make my work in other class easier.
Settings is setting class in .NET you can click on project->properties->settings to generate this class. You can find this file in Debug folder that [...]]]></description>
			<content:encoded><![CDATA[<p>If you want direct connection from C# to MySQL you can use MySQL.Data library from <a href="http://dev.mysql.com/downloads/connector/net/1.0.html">this</a> resource. I&#8217;ve write down my own DataAccess class to make my work in other class easier.</p>
<p><em>Settings</em> is setting class in .NET you can click on project->properties->settings to generate this class. You can find this file in Debug folder that have .config extension.</p>
<p><span id="more-71"></span></p>
<p>Here is my Data Access class manage command from C# to MySQL database.</p>
<pre class="brush:csharp">
    public class DataAccess
    {
        static internal string GetConnectionString()
        {
            return String.Format("server={0};user id={1};Password={2};database={3}",
                Settings.Default.DbServer, Settings.Default.DbUserId, Settings.Default.DbPassword,
                Settings.Default.DbName);
        }

        static DataAccess()
        { }

        public static DataTable ExecuteSelectCommand(MySqlCommand command)
        {
            DataTable table = null;
            try
            {
                command.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                table = new DataTable();
                table.Load(reader);
                reader.Close();
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Data.ToString());
            }
            finally
            {
                command.Connection.Close();
            }
            return table;
        }

        public static MySqlCommand CreateCommand()
        {
            string dataProviderName = Settings.Default.DbProvoderName;
            string connectionString = GetConnectionString();
            MySqlConnection conn = new MySqlConnection();
            conn.ConnectionString = connectionString;
            MySqlCommand comm = conn.CreateCommand();
            return comm;
        }

        public static int ExecuteNonQuery(MySqlCommand command)
        {
            int affectedRows = -1;
            try
            {
                command.Connection.Open();
                affectedRows = command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                command.Connection.Close();
            }
            return affectedRows;
        }
    }
</pre>
<p>Now here&#8217;s the sample to call that DataAccess class</p>
<pre class="brush:csharp">
    public class Golongan
    {
        private int idGolongan;
        private string namaGolongan;

        public int IdGolongan
        {
            get { return idGolongan; }
            set { idGolongan = value; }
        }

        public string NamaGolongan
        {
            get { return namaGolongan; }
            set { namaGolongan = value; }
        }

        public Golongan()
        { }

        public Golongan(int idGolongan, string namaGolongan)
        {
            this.idGolongan = idGolongan;
            this.namaGolongan = namaGolongan;
        }

        public static DataTable SelectAllGolongan()
        {
            MySqlCommand command = DataAccess.CreateCommand();
            command.CommandText = "select * from golongan";
            DataTable table = DataAccess.ExecuteSelectCommand(command);
            return table;
        }

        public int InsertGolongan()
        {
            MySqlCommand commmand = DataAccess.CreateCommand();
            commmand.CommandText = "insert into golongan (golongan) " +
                                    "values(    '" + this.namaGolongan + "')";

            return DataAccess.ExecuteNonQuery(commmand);
        }

        public int UpdateGolongan()
        {
            MySqlCommand commmand = DataAccess.CreateCommand();
            commmand.CommandText =
                String.Format("update golongan set golongan = '{0}' where idgolongan = {1}",
                this.namaGolongan, this.idGolongan);

            return DataAccess.ExecuteNonQuery(commmand);
        }

        public int DeleteGolongan()
        {
            MySqlCommand commmand = DataAccess.CreateCommand();
            commmand.CommandText =
                String.Format("delete from golongan where idgolongan = {0}",
                this.idGolongan);

            return DataAccess.ExecuteNonQuery(commmand);
        }
}
</pre>
<p>Hope it&#8217;s help<br />
Willy Achmat Fauzi</p>
]]></content:encoded>
			<wfw:commentRss>http://wcode.net/2009/10/csharp-with-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
