tag:blogger.com,1999:blog-35268635874847006762024-02-19T07:42:41.992-08:00Research is Fun!Just simply what i see and researchlauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-3526863587484700676.post-91938765190467320422012-09-04T08:30:00.001-07:002012-09-04T08:31:52.441-07:00building software applicationTutorial on how to create complete installer for windows. In this tutorial, it will show on how to include .net framework 3.5(for window XP)<br />
required software: visual studio 2008<br />
1. Add new project. choose "other project types", "setup and deployment", "setup project".<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmR0E5Z515l5Mgg_wY2mpzcSRC27J2IBWzSOjA7L2WanxIKwmRfm89OChxuwex1IqjrWxnGFY-MEx8dYlGmtVTvoGMJIe1l0qlbRP-zuGEckVAmK8NKleqLuW7VkMMP5mUnCqkiYlONMU/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmR0E5Z515l5Mgg_wY2mpzcSRC27J2IBWzSOjA7L2WanxIKwmRfm89OChxuwex1IqjrWxnGFY-MEx8dYlGmtVTvoGMJIe1l0qlbRP-zuGEckVAmK8NKleqLuW7VkMMP5mUnCqkiYlONMU/s320/1.png" width="270" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs-_FRzuQYvhDJX2rJ2lrYmOGpIsct6BWiM-yGfT1mnrHqNqDgRlvLql8bqRgJxT7L2MfWRlwrG1yUtBxgpcGArQxmn8nIFNGB9Bp71GuzXRZcuhQ5jcbEwueuPK7UFiThho-KBbDcHvU/s1600/0.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs-_FRzuQYvhDJX2rJ2lrYmOGpIsct6BWiM-yGfT1mnrHqNqDgRlvLql8bqRgJxT7L2MfWRlwrG1yUtBxgpcGArQxmn8nIFNGB9Bp71GuzXRZcuhQ5jcbEwueuPK7UFiThho-KBbDcHvU/s320/0.png" width="320" /></a></div>
2. add all exe and dll file into application folder<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJPZz-qcRDhN5l5QYWgDc7ylYdBSOEFYJ0l9QcK6eN7Jy_kcPiEXzLxDipqtponNp8oocER-EAyga_eX4goxjtx5_FUXDbw5sxZkZKxRGSXld-KT3VpACewglVk3fwoZlZ6MyVOwqgnPk/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJPZz-qcRDhN5l5QYWgDc7ylYdBSOEFYJ0l9QcK6eN7Jy_kcPiEXzLxDipqtponNp8oocER-EAyga_eX4goxjtx5_FUXDbw5sxZkZKxRGSXld-KT3VpACewglVk3fwoZlZ6MyVOwqgnPk/s1600/2.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
3. from .exe file, right click, "create shortcut to xxx.exe . cut this shortcut to user's desktop and user's programs menu</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCbb2ZBbXpmXtNWT2gZIIM8R6xd8G3xi7pGZXUXaEbcRjQiGENReU9v1cJcoWDJKquGJbHlOvQx4kvfI3q_OSbzTKWoHn27NNdr8KQvVckYi9eqVNBV4GQuOBC9BPMK4ozWyhyigG5WW4/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCbb2ZBbXpmXtNWT2gZIIM8R6xd8G3xi7pGZXUXaEbcRjQiGENReU9v1cJcoWDJKquGJbHlOvQx4kvfI3q_OSbzTKWoHn27NNdr8KQvVckYi9eqVNBV4GQuOBC9BPMK4ozWyhyigG5WW4/s1600/3.png" /></a></div>
4.right click on project, click properties.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlw8bo_xa5ZxrVwvWSCkoi7Lo2pZ8cu73UsFSNcndTyPYZBrc7_on6DumciT20zDm03QdUsZPt4lqLcuw5QwabRfzj6ThKZ-jW8f4v4nuxf3G39dtqt7jCXufa8vnwbHxiaNhiRW7q4jk/s1600/8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="221" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlw8bo_xa5ZxrVwvWSCkoi7Lo2pZ8cu73UsFSNcndTyPYZBrc7_on6DumciT20zDm03QdUsZPt4lqLcuw5QwabRfzj6ThKZ-jW8f4v4nuxf3G39dtqt7jCXufa8vnwbHxiaNhiRW7q4jk/s320/8.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
5. Click on "Prerequisites". Choose Crystal report basics for visual studio 2008(x86,x64) and "microsoft visual studio 2008 report viewer". Choose Download prerequisites from the same location as my application. Click ok.</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglazoJ7AEgwwuGfldE9e5sHDmcODPhKC-xNAyUsTJW5J4uHSAEaLj_07KhVTMvdSXnPN0S8YdfXm9AQYlIZINGkjoboVF7S5hqxpmuWQP0PO9YvH0-ZccRDPJpSUIgC1OEVMSsYWyHGoQ/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEglazoJ7AEgwwuGfldE9e5sHDmcODPhKC-xNAyUsTJW5J4uHSAEaLj_07KhVTMvdSXnPN0S8YdfXm9AQYlIZINGkjoboVF7S5hqxpmuWQP0PO9YvH0-ZccRDPJpSUIgC1OEVMSsYWyHGoQ/s320/5.png" width="288" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
6. At last, click build. Done.</div>
<br />lauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.com0tag:blogger.com,1999:blog-3526863587484700676.post-64321229794078680772012-05-10T08:43:00.000-07:002012-05-10T08:43:32.012-07:00Bind Datatable with Database<br />
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;">Recently
research on datatable bind with database. </span> Those programmers are
brilliant to create binding method.<o:p></o:p></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;">Let’s
see how to use it.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;">database structure:</span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-size: medium; line-height: 20px;">CREATE TABLE testdecimal (</span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"> `c1` decimal(10,8) DEFAULT NULL,</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"> `c2` decimal(10,8) DEFAULT NULL,</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"> `id` double NOT NULL AUTO_INCREMENT,</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"> PRIMARY KEY (`id`)</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;">) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;">insert some data to test</span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga18pKXHXknPBwUJU9Wvne0rlBTVJ7KEbRQQb45nEKiKtQlrdNAPgGD2cCHANFvTAPIsElbd0Ygehz8VMbHmxFrz8w02u3pD_Jmrx03sj6tBdZ6B0WvxCLiDHPKEYhgttzWSlFAM1zaSk/s1600/Untitled.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga18pKXHXknPBwUJU9Wvne0rlBTVJ7KEbRQQb45nEKiKtQlrdNAPgGD2cCHANFvTAPIsElbd0Ygehz8VMbHmxFrz8w02u3pD_Jmrx03sj6tBdZ6B0WvxCLiDHPKEYhgttzWSlFAM1zaSk/s1600/Untitled.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
code look like this:</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;">MySqlConnection</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> conn = <span style="color: blue;">new</span> <span style="color: #2b91af;">MySqlConnection</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> conn.ConnectionString = <span style="color: #a31515;">"server=testbed-pc;user id=root;password=123;Database=test;charset=utf8;"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">try<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">MySqlDataAdapter</span>
da = <span style="color: blue;">new</span> <span style="color: #2b91af;">MySqlDataAdapter</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> da.SelectCommand = <span style="color: blue;">new</span> <span style="color: #2b91af;">MySqlCommand</span>(<span style="color: #a31515;">"select * from testdecimal where c1 =10"</span>,
conn);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">MySqlCommandBuilder</span>
cb = <span style="color: blue;">new</span> <span style="color: #2b91af;">MySqlCommandBuilder</span>(da);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> da.Fill(testdecimal);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">while</span>
(i < testdecimal.Rows.Count)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> testdecimal.Rows[i][<span style="color: #a31515;">"c2"</span>] = 2 + i ;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> i++;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> da.Update(testdecimal);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">catch</span>
(<span style="color: #2b91af;">Exception</span> er)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">MessageBox</span>.Show(er.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> conn.Close();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> <span style="color: blue;">finally</span>
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-no-proof: yes;"> conn.Close();<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Courier New"; font-size: 10.0pt; line-height: 115%; mso-no-proof: yes;">
}</span><o:p></o:p></div>
<br />
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-size: medium;"><span style="line-height: 20px;">when execute, all rows with c1 =10 updated! database update successfully! fast and convenient way!</span></span></div>
<br />lauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.com0tag:blogger.com,1999:blog-3526863587484700676.post-18040749949589928332012-04-07T08:35:00.000-07:002012-04-07T08:37:15.902-07:00Import csv file to MySql Database<br />
<div class="MsoNormal">
Recently looking for ways to Import data from csv file to
MySql database. Mysql database has powerful
feature that allows user to import csv file directly to database. Sample code shows below:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
create table statement:</div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-size: x-small;">DROP TABLE IF EXISTS `share_market`.`klse`;</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">CREATE TABLE `share_market`.`klse` (</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `dates` date DEFAULT NULL,</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `opens` decimal(10,4) DEFAULT '0.0000',</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `highs` decimal(10,4) DEFAULT '0.0000',</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `lows` decimal(10,4) DEFAULT '0.0000',</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `closes` decimal(10,4) DEFAULT '0.0000',</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;"> `volumn` decimal(20,4) DEFAULT '0.0000'</span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">) ENGINE=InnoDB DEFAULT CHARSET=utf8;</span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
command to import csv file:<br />
<div class="MsoNormal">
<span style="font-size: x-small;">LOAD DATA LOCAL INFILE 'd:\klci analysis.csv'<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">into table klse<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">FIELDS TERMINATED BY ','<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">LINES TERMINATED BY '\n'<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: x-small;">(dates, opens, highs,lows,closes, volumn);<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
where table name is "klse", field name is "dates", "opens", "highs","lows","closes" and "volumn"</div>
<div class="MsoNormal">
Use "s" for each field to avoid reserve word "open" and "close"</div>
<div class="MsoNormal">
<br /></div>lauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.com0tag:blogger.com,1999:blog-3526863587484700676.post-21085399740011865072012-04-03T08:23:00.000-07:002012-04-03T08:26:31.763-07:00Float, Double and DecimalThere are many ways to store number value. Let’s pick three variable types of numbers that we always use: float, double and decimal. What are those differences?<br />
<div class="MsoNormal">
<span style="line-height: 18px;"><br /></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; margin-left: 0.5in; margin-right: 0in; margin-top: 0in; text-indent: 0.5in;">
<span style="font-family: 'Courier New'; font-size: x-small;"></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; margin-left: 0.5in; margin-right: 0in; margin-top: 0in; text-indent: 0.5in;">
</div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: x-small;"><span style="color: blue; font-size: 10pt;">decimal</span><span style="font-size: 10pt;"> dd <span style="color: blue;">=
</span>1234567890.123456789712345678971234567897M;<span style="color: blue;"><o:p></o:p></span></span></span></div>
<span style="font-family: 'Courier New'; font-size: x-small;">
</span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: x-small;"><span style="font-size: 10pt;"><span style="color: blue;"> double</span>
db <span style="color: blue;">= </span><span style="color: #2b91af;">Convert</span>.ToDouble(dd) * 1;<span style="color: blue;"><o:p></o:p></span></span></span></div>
<span style="font-family: 'Courier New'; font-size: x-small;">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: 10pt;"><span style="color: blue;"> float</span>
fl<span style="color: blue;"> = (float)</span>dd * 1;<span style="color: blue;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: 10pt;"><span style="color: blue;"> decimal</span>
dc = dd * 1;<span style="color: blue;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: 10pt;"><span style="color: blue;"> </span>txtdecimal.Text = dc.ToString(<span style="color: #a31515;">"f20"</span>);<span style="color: blue;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: 10pt;"><span style="color: blue;"> </span>txtdouble.Text = db.ToString(<span style="color: #a31515;">"f20"</span>);<span style="color: blue;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: 10pt; line-height: 115%;"><span style="color: blue;">
</span>txtfloat.Text = fl.ToString(<span style="color: #a31515;">"f20"</span>);</span><span style="color: blue;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 10pt; line-height: 115%;"><br /></span></div>
</span><br />
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">result:</span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-r7OjjdF1Pk45EMV_mUQGZup5j5SMGGJabvRwkknp1YubkS3QAMQe7DfQLKuTdXVKtwFtWw8UioS9-OCIz_1IOB0oCDiOv-DJ8SSembrHLFD7C-6zeIB69XnS06PGaVA_VG-mxl3GFYE/s1600/numbers.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="167" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-r7OjjdF1Pk45EMV_mUQGZup5j5SMGGJabvRwkknp1YubkS3QAMQe7DfQLKuTdXVKtwFtWw8UioS9-OCIz_1IOB0oCDiOv-DJ8SSembrHLFD7C-6zeIB69XnS06PGaVA_VG-mxl3GFYE/s320/numbers.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: x-small;"><span style="line-height: 14px;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">1. float able to store 7 digit precision</span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">2. double can store 16 digit precision</span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">3. decimal can store up to 27 digit precision -> this is a surprise. even decimal can be out of range with less then 30 digit precision!</span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;">Currently I am researching on OpenCL and OpenCL
allows ONLY double and float variable. Therefore graphic card is not suitable
for task that requires high precision. OpenCL is more suitable for simulation
or mass calculation like CAD CAM tools. Will update more information on OpenCL
+ c# when research is done.</span><span style="font-size: 13.5pt; line-height: 115%;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"><br /></span></div>lauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.com0tag:blogger.com,1999:blog-3526863587484700676.post-17751082996510615832012-03-28T08:27:00.000-07:002012-03-28T08:30:33.414-07:00DataTable vs List<br />
<div class="MsoNormal">
<span style="line-height: 115%;"> Recently
just make in depth research about DataTable. DataTable is easy to use variable
which allows user to pool data into it with consistence format, embed with
other properties that allow us to do sorting, search etc. Currently I am
researching on high performance application, which need to store large amount
of data into memory. Soon I hit a bottleneck with DataTable. When inserting
more than 5 million of records into DataTable, my desktop starts to struggle, even with 5G Ram So
I need to find an alternative. <o:p></o:p></span><br />
<span style="line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;"> The
main purpose of my tool is analyzing large
amount of data. It uses to compare ID and do heavy calculation on selected
field. After do some research, I found list can on par with DataTable’s needed
function, at the same time increase efficiency. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 115%;">So
lets prove it!<span style="font-size: medium;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;">DataTable
button click event<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">private</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">void</span> button3_Click(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">Stopwatch</span>
stopwatch = <span style="color: blue;">new</span> <span style="color: #2b91af;">Stopwatch</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> stopwatch.Start();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">DataTable</span>
dt = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataTable</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Columns.Add(<span style="color: #a31515;">"a"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Columns.Add(<span style="color: #a31515;">"b"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Columns.Add(<span style="color: #a31515;">"c"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Columns.Add(<span style="color: #a31515;">"d"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Columns.Add(<span style="color: #a31515;">"e"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">long</span>
i = 0;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">while</span>
(i < 1000000)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> dt.Rows.Add(<span style="color: #a31515;">"a"</span> + i.ToString(),<span style="color: #a31515;">"b"</span> + i.ToString(), <span style="color: #a31515;">"c"</span> + i.ToString(), <span style="color: #a31515;">"d"</span> + i.ToString(), <span style="color: #a31515;">"e"</span> + i.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> i++;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> stopwatch.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(stopwatch.Elapsed.TotalMilliseconds.ToString());<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: 'Courier New'; font-size: 10pt; line-height: 115%;"> }</span><span style="font-size: 13.5pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 13.5pt; line-height: 115%;">List button click event<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: 'Courier New'; font-size: 10pt;">private</span><span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">void</span> button4_Click(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">Stopwatch</span>
stopwatch = <span style="color: blue;">new</span> <span style="color: #2b91af;">Stopwatch</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> stopwatch.Start();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">List</span><<span style="color: #2b91af;">lst</span>>>
lists = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">List</span><<span style="color: #2b91af;">lst</span>>>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">long</span>
i = 0;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">while</span>
(i < 1000000)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">lst</span>> list = <span style="color: blue;">new</span>
<span style="color: #2b91af;">List</span><<span style="color: #2b91af;">lst</span>>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">lst</span>
superlist = <span style="color: blue;">new</span> <span style="color: #2b91af;">lst</span>
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> field1 = <span style="color: #a31515;">"a"</span> + i.ToString(),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> field2 = <span style="color: #a31515;">"b"</span> + i.ToString(),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> field3 = <span style="color: #a31515;">"c"</span> + i.ToString(),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> field4 = <span style="color: #a31515;">"d"</span> + i.ToString(),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> field5 = <span style="color: #a31515;">"e"</span> + i.ToString()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> lists.Add(list);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> i++;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> stopwatch.Stop();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: #2b91af;">MessageBox</span>.Show(stopwatch.Elapsed.TotalMilliseconds.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">lst<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">public</span>
<span style="color: blue;">string</span> field1 { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">public</span>
<span style="color: blue;">string</span> field2 { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">public</span>
<span style="color: blue;">string</span> field3 { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">public</span>
<span style="color: blue;">string</span> field4 { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> <span style="color: blue;">public</span>
<span style="color: blue;">string</span> field5 { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: 'Courier New'; font-size: 10pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Benchmark result:<o:p></o:p></div>
<div class="MsoNormal">
datatable memory usage</div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTLaf6JOhMRvGrLy5d6HmgYJVlgpjvwsGM3bfLgRM3TGVAfb0rKDgidhotiJ9bXcaII8i8e-pHNVgIsgaAKPz6jIauBBKrvuAHmdalVw33BdEMu1-yDBig0FwVQbXfkEYiOqKlkRk_yiM/s1600/dtwtm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTLaf6JOhMRvGrLy5d6HmgYJVlgpjvwsGM3bfLgRM3TGVAfb0rKDgidhotiJ9bXcaII8i8e-pHNVgIsgaAKPz6jIauBBKrvuAHmdalVw33BdEMu1-yDBig0FwVQbXfkEYiOqKlkRk_yiM/s320/dtwtm.png" width="287" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
list memory usage</div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIKmLR7gXok81Bvq05OWd8UDzf09JXUuN5-nzCnpeF9D0VEfWPTDQQlsx7JC25SO0zIw5sPOBi5NyGvieWzt8BRAGf5uaXtR3emnsFxKJAllz1V5flp7AT7LUiaiMc9MwohyNr5x_0Oj4/s1600/listwtm.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIKmLR7gXok81Bvq05OWd8UDzf09JXUuN5-nzCnpeF9D0VEfWPTDQQlsx7JC25SO0zIw5sPOBi5NyGvieWzt8BRAGf5uaXtR3emnsFxKJAllz1V5flp7AT7LUiaiMc9MwohyNr5x_0Oj4/s320/listwtm.png" width="287" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
time taken in milisecond, for DataTable</div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUT6UeQYdaRZvakebyXJ8ggk9LpLNj-dqmSS8v5uXlB0yjN8pjwbWioI5QC4Wp4MFcGVPMHAY5cb0Su3JYoJ5Fktyk8Y34GDtcV2cmrnb2D7Ff7rSxj87ln-ShFqHX5nnZXnu1l9FMSzU/s1600/dtstopwatch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUT6UeQYdaRZvakebyXJ8ggk9LpLNj-dqmSS8v5uXlB0yjN8pjwbWioI5QC4Wp4MFcGVPMHAY5cb0Su3JYoJ5Fktyk8Y34GDtcV2cmrnb2D7Ff7rSxj87ln-ShFqHX5nnZXnu1l9FMSzU/s1600/dtstopwatch.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="text-align: -webkit-auto;">time taken in milisecond, for List</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0F7UnKIi95XieSW2JrOHL-Rd1-JHsXmhDwyO6mcZJ0K7yBB8b0SMe8Ww-_328IkL8_53Vo3HAm_ddf9RKo8xGfCzkGbDs-THCgYMRmZ7SNWasRvFNRkFcKr_mmmPv4fdQAy17oGhSisg/s1600/listsw.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0F7UnKIi95XieSW2JrOHL-Rd1-JHsXmhDwyO6mcZJ0K7yBB8b0SMe8Ww-_328IkL8_53Vo3HAm_ddf9RKo8xGfCzkGbDs-THCgYMRmZ7SNWasRvFNRkFcKr_mmmPv4fdQAy17oGhSisg/s1600/listsw.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
List is 4X faster then datatable</div>
<div class="separator" style="clear: both; text-align: left;">
DataTable uses 6X more memory then list</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
Conclusion:</div>
<div class="separator" style="clear: both; text-align: left;">
there are some performance tweak can be done on source code. </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="text-align: -webkit-auto;"><br /></span></div>
<div class="MsoNormal">
<br /></div>lauhttp://www.blogger.com/profile/14010914615685548373noreply@blogger.com18