<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Linglom&#039;s blog &#187; VB.NET</title>
	<atom:link href="http://www.linglom.com/category/programming/vb-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linglom.com</link>
	<description>Just another IT weblog</description>
	<lastBuildDate>Thu, 27 May 2010 09:56:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</title>
		<link>http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/</link>
		<comments>http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/#comments</comments>
		<pubDate>Thu, 27 May 2010 09:40:36 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Chart]]></category>
		<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=1153</guid>
		<description><![CDATA[From Part 1: Basic Chart and Part 2: Customize Chart, you see how to create a basic chart using GUI (no coding). But the chart is static, it&#8217;s lack flexibility which means that you cannot change properties or data of the chart while the application is running. Therefore, I will show how to create a [...]


Related posts:<ol><li><a href='http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 2: Customize Chart'>Creating Graph with VB.NET, Part 2: Customize Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 1: Basic Chart'>Creating Graph with VB.NET, Part 1: Basic Chart</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p>From Part 1: Basic Chart and Part 2: Customize Chart, you see how to create a basic chart using GUI (no coding). But the chart is static, it&#8217;s lack flexibility which means that you cannot change properties or data of the chart while the application is running. Therefore, I will show how to create a chart by coding and bind data from a SQL Server&#8217;s database to the Chart control.</p>
<p><span id="more-1153"></span></p>
<p><!-- Start AdLogger Wrapping Code -->
<?php @include_once("/usr/local/psa/home/vhosts/linglom.com/httpdocs/adlogger/ad_check_include.php"); if ($show_ads == 'y') { ?>

<script type="text/javascript"><!--
google_ad_client = "pub-7765165459812980";
google_ad_width = 300;
google_ad_height = 250;
google_ad_format = "300x250_as";
google_ad_type = "text_image";
//2007-02-17: SquareonBlog
google_ad_channel = "6055254908";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "ce6531";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

<?php } ?>
<!-- End AdLogger Wrapping Code --></p>
<p>On this example, I will create a connection to &#8220;<strong>Northwind</strong>&#8221; database on this SQL Server &#8220;<strong>BKKSQL001\INSTANCE01</strong>&#8221; and query product name and units in stock from &#8220;<strong>Products</strong>&#8221; table. Then, I create a chart and bind the query&#8217;s result to the chart.</p>
<h3>Step-by-step</h3>
<ol>
<li>Create a new Windows Application project on VB.NET and type name as &#8220;<strong>SampleDataBindChart</strong>&#8220;.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/_1.png" width="200" height="122" alt="Create New VB.NET's Windows Application" title="Create New VB.NET's Windows Application"  /></a></li>
<li>On <strong>Form1</strong>, open code window and import these libraries. The first two libraries are used for SQL. The last one is used for Chart.

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Data</span>.<span style="color: #0000FF;">SqlClient</span>
&nbsp;
<span style="color: #0600FF;">Imports</span> System.<span style="color: #0000FF;">Windows</span>.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DataVisualization</span>.<span style="color: #0000FF;">Charting</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/_2.png" width="200" height="122" alt="Import Required Libraries" title="Import Required Libraries"  /></a></li>
<li>Type code below on Form1_Load().

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">        <span style="color: #0600FF;">Dim</span> strConn <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Data Source=BKKSQL001\INSTANCE01;&quot;</span> <span style="color: #008000;">&amp;</span> _
            <span style="color: #808080;">&quot;Initial Catalog=Northwind;Integrated Security=True&quot;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> conn <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlConnection<span style="color: #000000;">&#40;</span>strConn<span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> sqlProducts <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;SELECT Top 8 ProductName, UnitsInStock FROM Products&quot;</span>
        <span style="color: #0600FF;">Dim</span> da <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> SqlDataAdapter<span style="color: #000000;">&#40;</span>sqlProducts, conn<span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> ds <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        da.<span style="color: #0000FF;">Fill</span><span style="color: #000000;">&#40;</span>ds, <span style="color: #808080;">&quot;Products&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Dim</span> ChartArea1 <span style="color: #FF8000;">As</span> ChartArea <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> ChartArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> Legend1 <span style="color: #FF8000;">As</span> Legend <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> Legend<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> Series1 <span style="color: #FF8000;">As</span> Series <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> Series<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Dim</span> Chart1 <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> Chart<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Chart1<span style="color: #000000;">&#41;</span>
&nbsp;
        ChartArea1.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;ChartArea1&quot;</span>
        Chart1.<span style="color: #0000FF;">ChartAreas</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>ChartArea1<span style="color: #000000;">&#41;</span>
        Legend1.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Legend1&quot;</span>
        Chart1.<span style="color: #0000FF;">Legends</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Legend1<span style="color: #000000;">&#41;</span>
        Chart1.<span style="color: #0000FF;">Location</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> System.<span style="color: #0000FF;">Drawing</span>.<span style="color: #0000FF;">Point</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">13</span>, <span style="color: #FF0000;">13</span><span style="color: #000000;">&#41;</span>
        Chart1.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Chart1&quot;</span>
        Series1.<span style="color: #0000FF;">ChartArea</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;ChartArea1&quot;</span>
        Series1.<span style="color: #0000FF;">Legend</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Legend1&quot;</span>
        Series1.<span style="color: #0000FF;">Name</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Series1&quot;</span>
        Chart1.<span style="color: #0000FF;">Series</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Series1<span style="color: #000000;">&#41;</span>
        Chart1.<span style="color: #0000FF;">Size</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">New</span> System.<span style="color: #0000FF;">Drawing</span>.<span style="color: #0000FF;">Size</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">800</span>, <span style="color: #FF0000;">400</span><span style="color: #000000;">&#41;</span>
        Chart1.<span style="color: #0000FF;">TabIndex</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
        Chart1.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Chart1&quot;</span>
&nbsp;
        Chart1.<span style="color: #0000FF;">Series</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Series1&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">XValueMember</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;ProductName&quot;</span>
        Chart1.<span style="color: #0000FF;">Series</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Series1&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">YValueMembers</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;UnitsInStock&quot;</span>
&nbsp;
        Chart1.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Products&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><strong>Code Explanation</strong>:</p>
<ul>
<li>Line 1-2: Define a connection string to connect to a database on SQL Server.
<ul>
<li><strong>Data Source</strong> is a SQL Server name.</li>
<li><strong>Initial Catalog</strong> is a database name.</li>
<li>Set <strong>Integrated Security=True</strong> to use the current user as identity to access the SQL Server database.</li>
</ul>
</li>
<li>Line 4: Create a SqlConnection&#8217;s object.</li>
<li>Line 6: Define SQL query string.</li>
<li>Line 7-9: Execute the query and populate result to DataSet&#8217;s object.</li>
<li>Line 11-14: Create Chart&#8217;s objects.</li>
<li>Line 15: Add Chart&#8217;s object to the form.</li>
<li>Line 17-29: Set Chart&#8217;s properties (ChartArea, Legend and Series).</li>
<li>Line 31-32: Bind column &#8220;<strong>ProductName</strong>&#8221; to X-axis and column &#8220;<strong>UnitsInStock</strong>&#8221; to Y-axis on the &#8220;<strong>Series1</strong>&#8221; Chart.</li>
<li>Line 34: Set Chart&#8217;s data source to the DataTable in the DataSet&#8217;s object.</li>
</ul>
<p><a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/_3.png" width="200" height="150" alt="Form1_Load's code" title="Form1_Load's code"  /></a></li>
<li>Run the project. You see a chart displaying &#8220;<strong>Product Name</strong>&#8221; on X-axis and &#8220;<strong>Unit in Stock</strong>&#8221; on Y-axis which data is gathered from Northwind database on SQL Server.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-3/_4.png" width="200" height="121" alt="A chart binding to Database on SQL Server" title="A chart binding to Database on SQL Server"  /></a></li>
</ol>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 2: Customize Chart'>Creating Graph with VB.NET, Part 2: Customize Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 1: Basic Chart'>Creating Graph with VB.NET, Part 1: Basic Chart</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Creating Graph with VB.NET]]></series:name>
	</item>
		<item>
		<title>Creating Graph with VB.NET, Part 2: Customize Chart</title>
		<link>http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/</link>
		<comments>http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/#comments</comments>
		<pubDate>Fri, 14 May 2010 07:45:20 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Chart]]></category>
		<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=1151</guid>
		<description><![CDATA[On Part 1: Basic Chart, I show how to create a basic chart with default chart type and color style. Now you will see how to customize those properties on a chart. Sections Sample chart Change chart type Change color style Insert title to chart 3D chart Sample chart The sample chart that I use [...]


Related posts:<ol><li><a href='http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 1: Basic Chart'>Creating Graph with VB.NET, Part 1: Basic Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 3: Data Binding Chart to Database'>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p>On Part 1: Basic Chart, I show how to create a basic chart with default chart type and color style. Now you will see how to customize those properties on a chart.</p>
<p><span id="more-1151"></span></p>
<p><!--adsense#Square--></p>
<p><a name="top"></a></p>
<h3>Sections</h3>
<ul>
<li><a href="#1">Sample chart</a></li>
<li><a href="#2">Change chart type</a></li>
<li><a href="#3">Change color style</a></li>
<li><a href="#4">Insert title to chart</a></li>
<li><a href="#5">3D chart</a></li>
</ul>
<p><a name="1"></a></p>
<h3>Sample chart</h3>
<p>The sample chart that I use on this post has a series &#8220;<strong>Series1</strong>&#8221; which has 3 data points &#8220;<strong>10,20,30</strong>&#8220;.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/1.png" target="_blank"><img title="Sample chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_1.png" alt="Sample chart" width="200" height="215" /></a></p>
<p><a href="#top">Back to top</a></p>
<p><a name="2"></a></p>
<h3>Change chart type</h3>
<p>There are many chart types that you can select for Chart control. On this example, I show some of those chart types which are Point, Line, Bar, Pie.</p>
<ol>
<li>On <strong>Chart Properties</strong>, click the <strong>Series</strong> collection. Then, click the ellipsis button.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/2.png" target="_blank"><img title="Chart Properties" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_2.png" alt="Chart Properties" width="200" height="282" /></a></li>
<li>On <strong>Series Collection Editor</strong>, select &#8220;<strong>Series1</strong>&#8221; in the Members area and change the <strong>Chart type</strong> property to <strong>Point</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/3.png" target="_blank"><img title="Change Chart Type" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_3.png" alt="Change Chart Type" width="200" height="147" /></a></li>
<li>The <strong>Point</strong> chart type.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/4.png" target="_blank"><img title="Point Chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_4.png" alt="Point Chart" width="200" height="215" /></a></li>
<li>The <strong>Line</strong> chart type.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/5.png" target="_blank"><img class=" alignnone" title="Line Chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_5.png" alt="Line Chart" width="200" height="215" /></a>
</li>
<li>The <strong>Bar</strong> chart type.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/6.png" target="_blank"><img title="Bar Chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_6.png" alt="Bar Chart" width="200" height="215" /></a></li>
<li>The <strong>Pie</strong> chart type.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/7.png" target="_blank"><img title="Pie Chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_7.png" alt="Pie Chart" width="200" height="215" /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
<p><a name="3"></a></p>
<h3>Change Color style of chart</h3>
<p>There are many color palettes that you can choose for Chart control. This section shows how to change color of Chart control.</p>
<ol>
<li>On <strong>Chart Properties</strong>, click on <strong>Palette</strong> property. You see a drop down button. Click on it and you can choose a color palette for your chart.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/8.png" target="_blank"><img title="Change Color Palette" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_8.png" alt="Change Color Palette" width="200" height="249" /></a></li>
<li>The example below is <strong>Bright</strong> color palette.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/9.png" target="_blank"><img title="Sample Chart" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_9.png" alt="Sample Chart" width="200" height="215" /></a>
</li>
</ol>
<p><a href="#top">Back to top</a></p>
<p><a name="4"></a></p>
<h3>Insert title to chart</h3>
<p>This section shows how to insert title to Chart control.</p>
<ol>
<li>On <strong>Chart Properties</strong>, click the <strong>Title</strong> collection. Then, click the ellipsis button.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/10.png" target="_blank"><img title="Chart Properties" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_10.png" alt="Chart Properties" width="200" height="249" /></a></li>
<li>On <strong>Title Collection Editor</strong>, click <strong>Add</strong> and set <strong>(Text)</strong> to &#8220;<strong>My Sample Chart</strong>&#8221; in the newly created Title object.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/11.png" target="_blank"><img title="Add Title" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_11.png" alt="Add Title" width="200" height="147" /></a></li>
<li>Run the project. You will see a title on top of the chart.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/12.png" target="_blank"><img title="Sample Chart with title" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_12.png" alt="Sample Chart with title" width="200" height="215" /></a></li>
<li>You can customize title&#8217;s text style, title position, title color on title properties.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/13.png" target="_blank"><img title="Title Properties" src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_13.png" alt="Title Properties" width="200" height="147" /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
<p><a name="5"></a></p>
<h3>3D chart</h3>
<p>This section shows how to use three-dimensional (3D) chart areas in Chart control.</p>
<ol>
<li>On <strong>Chart Properties</strong>, click the <strong>ChartAreas</strong> collection. Then, click the ellipsis button.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/14.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_14.png" width="200" height="249" alt="Open ChartArea Collection Editor" title="Open ChartArea Collection Editor"  /></a></li>
<li>On <strong>ChartArea Collection Editor</strong>, select &#8220;<strong>ChartArea1</strong>&#8220;. Expand <strong>Area3DStyle</strong> and change <strong>(Enable3D)</strong> to <strong>True</strong>.<br />
<em><strong>Note:</strong></em> You can customize your 3D Style on this <strong>Area3DStyle</strong> properties .<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/15.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_15.png" width="200" height="147" alt="Enable 3D Chart" title="Enable 3D Chart"  /></a></li>
<li>You see the chart is now 3D.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/16.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-2/_16.png" width="200" height="215" alt="Sample 3D Chart" title="Sample 3D Chart"  /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 1: Basic Chart'>Creating Graph with VB.NET, Part 1: Basic Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 3: Data Binding Chart to Database'>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<series:name><![CDATA[Creating Graph with VB.NET]]></series:name>
	</item>
		<item>
		<title>Creating Graph with VB.NET, Part 1: Basic Chart</title>
		<link>http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/</link>
		<comments>http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/#comments</comments>
		<pubDate>Tue, 11 May 2010 04:21:33 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Chart]]></category>
		<category><![CDATA[Dot Net]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=1148</guid>
		<description><![CDATA[This series shows how to create chart or graph with VB.NET using Microsoft Chart Controls for .NET Framework. I divide the series into 3 parts: Creating Graph with VB.NET, Part 1: Basic Chart Creating Graph with VB.NET, Part 2: Customize Chart Creating Graph with VB.NET, Part 3: Data Binding Chart to Database On this post, [...]


Related posts:<ol><li><a href='http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 2: Customize Chart'>Creating Graph with VB.NET, Part 2: Customize Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 3: Data Binding Chart to Database'>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p>This series shows how to create chart or graph with VB.NET using Microsoft Chart Controls for .NET Framework.</p>
<p><span id="more-1148"></span></p>
<p>I divide the series into 3 parts:</p>
<ol>
<li>Creating Graph with VB.NET, Part 1: Basic Chart</li>
<li>Creating Graph with VB.NET, Part 2: Customize Chart</li>
<li>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</li>
</ol>
<p><!--adsense#Square--></p>
<p>On this post, you will learn how to create a basic chart on Windows Form Application with VB.NET. I use Microsoft Visual Studio 2005 as IDE.</p>
<h3>Requirement</h3>
<ul>
<li>Microsoft Visual Studio 2005 or later.</li>
<li>.NET Framework 3.5 SP1 or later. You can download <a href="http://www.microsoft.com/downloads/details.aspx?familyid=AB99342F-5D1A-413D-8319-81DA479AB0D7&#038;displaylang=en" target="_blank" rel="nofollow">Microsoft .NET Framework 3.5 Service Pack 1</a> from Microsoft website.</li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C&#038;displaylang=en" target="_blank" rel="nofollow">Microsoft Chart Controls for Microsoft .NET Framework 3.5</a></li>
</ul>
<h3>Step-by-step</h3>
<ol>
<li>Install the requirement software as stated on the Requirement section.</li>
<li>Open Microsoft Visual Studio 2005. Create a new VB.NET&#8217;s Windows Application. Type the name of the project as &#8220;<strong>SampleBasicChart</strong>&#8220;.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_1.png" width="200" height="122" alt="Create Windows Application's Project" title="Create Windows Application's Project"  /></a></li>
<li>On <strong>Toolbox</strong> window, drag a <strong>Chart</strong> control from the <strong>Data</strong> category to the Windows Form.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_2.png" width="200" height="188" alt="A Chart Control" title="A Chart Control"  /></a><br />
<strong><em>Note</em></strong>: If you does not see the Chart control in the Toolbox, you need to perform these steps below:</p>
<ul>
<li>Right-click on the <strong>Toolbox</strong> window and select <strong>Choose Items</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_3.png" width="200" height="158" alt="Add New Item to Toolbox" title="Add New Item to Toolbox"  /></a></li>
<li>On <strong>Choose Toolbox Items</strong>, click Browse.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_4.png" width="200" height="143" alt="Browse the Component" title="Browse the Component"  /></a></li>
<li>Browse to the location where you have installed Microsoft Chart Controls. The default location is<br />
C:\Program Files\Microsoft Chart Controls\Assemblies and select <strong>System.Windows.Forms.DataVisualization.dll</strong>. Then, click <strong>Open</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_5.png" width="200" height="131" alt="System.Windows.Forms.DataVisualization.dll" title="System.Windows.Forms.DataVisualization.dll"  /></a></li>
<li>You see Chart control has been added to .NET Framework Components. Verify that its check box is checked and click <strong>OK</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_6.png" width="200" height="143" alt="Chat Control Component" title="Chat Control Component"  /></a></li>
</ul>
</li>
<li>On <strong>Chart Properties</strong>, you see an empty chart with a default series, &#8220;<strong>Series1</strong>&#8220;. Next, I&#8217;m going to add another Series. On <strong>Chart Properties</strong>, click the <strong>Series</strong> collection. Then, click the ellipsis button.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/7.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_7.png" width="200" height="250" alt="Chart Properties" title="Chart Properties"  /></a></li>
<li>On <strong>Series Collection Editor</strong>, click <strong>Add</strong>. You will see &#8220;<strong>Series2</strong>&#8221; has been added to the collection.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/8.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_8.png" width="200" height="147" alt="Series Collection Editor" title="Series Collection Editor"  /></a></li>
<li>Now you have two series on a chart. But there is not any data on the chart so I will add some example data point on each series. Select <strong>Series1</strong> and click the ellipsis button on <strong>Points</strong> collection.
</li>
<li>On <strong>Series Collection Editor</strong>, select &#8220;<strong>Series1</strong>&#8221; in the <strong>Members</strong> area and click the <strong>Points</strong> collection property. Then, click the ellipsis button.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/9.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_9.png" width="200" height="147" alt="Add Data Points" title="Add Data Points"  /></a></li>
<li>On <strong>DataPoint Collection Editor</strong>, click <strong>Add</strong> and assign a value &#8220;<strong>10</strong>&#8221; to the <strong>YValues</strong> property in the newly created DataPoint object.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/10.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_10.png" width="200" height="147" alt="Set YValues on DataPoint" title="Set YValues on DataPoint"  /></a></li>
<li>Repeat step 8 to add two more DataPoint object with values &#8220;<strong>20</strong>&#8221; and &#8220;<strong>30</strong>&#8221; repectively. Then, click <strong>OK</strong> to close the <strong>DataPoint Collection Editor</strong> window.<br />
<em><strong>Note</strong></em>:  These values are example values, you may use any value as you want.</li>
<li>Repeat step 7-9 again on &#8220;<strong>Series2</strong>&#8221; with <strong>YValues</strong> as you want. Then, click <strong>OK</strong> to close the <strong>Series Collection Editor</strong> windows.</li>
<li>Run the project. You see the chart with two series as you created.<br />
<a href="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/11.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/Dot-Net/Chart-Control/Part-1/_11.png" width="200" height="215" alt="A Basic Chart" title="A Basic Chart"  /></a></li>
</ol>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2010/05/14/creating-graph-with-vb-net-part-2-customize-chart/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 2: Customize Chart'>Creating Graph with VB.NET, Part 2: Customize Chart</a></li>
<li><a href='http://www.linglom.com/2010/05/27/creating-graph-with-vb-net-part-3-data-binding-chart-to-database/' rel='bookmark' title='Permanent Link: Creating Graph with VB.NET, Part 3: Data Binding Chart to Database'>Creating Graph with VB.NET, Part 3: Data Binding Chart to Database</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2010/05/11/creating-graph-with-vb-net-part-1-basic-chart/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<series:name><![CDATA[Creating Graph with VB.NET]]></series:name>
	</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VIII: Display Result on GUI</title>
		<link>http://www.linglom.com/2009/05/29/accessing-mysql-on-vbnet-using-mysql-connectornet-part-viii-display-result-on-gui/</link>
		<comments>http://www.linglom.com/2009/05/29/accessing-mysql-on-vbnet-using-mysql-connectornet-part-viii-display-result-on-gui/#comments</comments>
		<pubDate>Fri, 29 May 2009 15:29:56 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=797</guid>
		<description><![CDATA[Introduction Actually, I don&#8217;t prepare to write this post while I was writing the series. But there are some people want to know how to display a query data on Windows form rather than in console window which I wrote in the previous post. So this post, I&#8217;ll show how to display a query data [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p><a name="top"></a></p>
<h3>Introduction</h3>
<p>Actually, I don&#8217;t prepare to write this post while I was writing the series. But there are some people want to know how to display a query data on Windows form rather than in console window which I wrote in the previous post. So this post, I&#8217;ll show how to display a query data on DataGridView on Windows form using MySqlDataAdapter.</p>
<p><span id="more-797"></span></p>
<p><!--adsense#Square--></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<h3>Section</h3>
<ol>
<li><a href="#1">Step-by-step</a></li>
<li><a href="#2">Download Code</a></li>
<li><a href="#3">Summary</a></li>
</ol>
<p><a name="1"></a></p>
<h3>Step-by-step</h3>
<ol>
<li>I&#8217;ll continue from the previous post. You can download a project file from the previous post at here &#8211; <a href="http://www.linglom.com/downloads/SampleMySQL.zip">SampleMySQL</a> (zip format). The project was created on Microsoft Visual Studio 2005.
</li>
<li>Open the Design view of <strong>Form1</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_1.png" width="200" height="146" alt="Windows Form's Design View" title="Windows Form's Design View"  /></a></li>
<li>Drag <strong>DataGridView</strong> tool from the <strong>Toolbox</strong> window to empty area on the form.<br />
Note: If you can&#8217;t find <strong>Toolbox</strong> window, select <strong>View</strong> -> <strong>Toolbox</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_2.png" width="200" height="146" alt="Add DataGridView to the form" title="Add DataGridView to the form"  /></a></li>
<li>The DataGridView is placed on the form. The dark background indicates the area of DataGridView&#8217;s object. On <strong>Properties</strong> window, you see the default name is <strong>DataGridView1</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_3.png" width="200" height="146" alt="DataGridView1" title="DataGridView1"  /></a></li>
<li>Back to the Form&#8217;s code view. Comment all the lines in <strong>Form1_Load</strong> method. These are the code from the previous post which I don&#8217;t want it to be executed.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_4.png" width="200" height="146" alt="Comment the previous code" title="Comment the previous code"  /></a></li>
<li>Copy the code below to the form as a new method. Notice that this method is similar to retriveData() method except that it use <strong>MySqlDataAdapter</strong> rather than MySqlDataReader.

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> retriveDataToDataGrid<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Try</span>
            <span style="color: #0600FF;">Dim</span> query <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;SELECT * FROM Country&quot;</span>
            <span style="color: #0600FF;">Dim</span> connection <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlConnection<span style="color: #000000;">&#40;</span>connStr<span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">Dim</span> da <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlDataAdapter<span style="color: #000000;">&#40;</span>query, connection<span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">Dim</span> ds <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> DataSet<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
            <span style="color: #0600FF;">If</span> da.<span style="color: #0000FF;">Fill</span><span style="color: #000000;">&#40;</span>ds<span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
                DataGridView1.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> ds.<span style="color: #0000FF;">Tables</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
            connection.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
        <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><em><strong>Code Explanation:</strong></em></p>
<ul>
<li>Line 3-5: Create New MySqlDataAdapter object with some parameters.</li>
<li>Line 6: Create an empty data set.</li>
<li>Line 8-10: Fills a data set and set data source of DataGridView1 to a table in the data set.</li>
<li>Line 12: Close the connection.</li>
</ul>
<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_5.png" width="200" height="146" alt="retriveDataToDataGrid" title="retriveDataToDataGrid"  /></a></li>
<li>Add code to the <strong>Form1_Load</strong> method to call retriveDataToDataGrid() when the form is loaded.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_6.png" width="200" height="146" alt="Add code on Form_Load method" title="Add code on Form_Load method"  /></a></li>
<li>Run the project. You&#8217;ll see the result on DataGridView on Windows form. You may adjust the size of DataGridView to suit your screen.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/7.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part8/_7.png" width="200" height="148" alt="The Query Result on DataGridView" title="The Query Result on DataGridView"  /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
<p><a name="2"></a></p>
<h3>Download Code</h3>
<p>You can download a complete project file at here &#8211; <a href="http://www.linglom.com/downloads/SampleMySQL2.zip">SampleMySQL2</a>. The project was created on Microsoft Visual Studio 2005.<br />
<a href="#top">Back to top</a></p>
<p><a name="3"></a></p>
<h3>Summary</h3>
<p>Now you have reach the end of the article. After 8 parts, you should be able to develop an simple application to access MySQL Server on your own. I think that the article is quite clear than other accessing database server articles that I wrote last year. If you have any question, feel free to leave a comment below.</p>
<h4>Reference</h4>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/connector-net-examples-mysqldataadapter.html" target="_blank" rel="nofollow">Using MySqlDataAdapter </a> on dev.mysql.com</li>
</ul>
<p><a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/05/29/accessing-mysql-on-vbnet-using-mysql-connectornet-part-viii-display-result-on-gui/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations</title>
		<link>http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/</link>
		<comments>http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 01:57:19 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=587</guid>
		<description><![CDATA[Perform SQL Operations From the previous part, I have successfully connect to world database on MySQL Server from VB.NET. Next, I try to perform basic SQL operations (SELECT, INSERT, UPDATE and DELETE) on the world database. Note: This post is continued from the previous part. If you start a new project, you&#8217;ll need to add [...]


Related posts:<ol><li><a href='http://www.linglom.com/2008/01/16/accessing-mysql-on-netbeans-using-jdbc-part-ii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations'>Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2007/07/14/accessing-sql-server-on-netbeans-using-jdbc-part-ii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations'>Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2009/09/07/accessing-ms-access-2007-on-netbeans-6-5-using-jdbc-part-4-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations'>Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p><a name="top"></a></p>
<h3>Perform SQL Operations</h3>
<p>From the previous part, I have successfully connect to <strong>world</strong> database on MySQL Server from VB.NET. Next, I try to perform basic SQL operations (SELECT, INSERT, UPDATE and DELETE) on the world database.<br />
<em><strong>Note:</strong></em> This post is continued from the previous part. If you start a new project, you&#8217;ll need to add <strong>MySql.Data</strong> reference. See the previous post for more detail.</p>
<p><span id="more-587"></span></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><!--adsense#Square--></p>
<h3>Section</h3>
<ol>
<li><a href="#1">Declare a Connection String</a></li>
<li><a href="#2">Retrieve Data from Database</a></li>
<li><a href="#3">Update Record on Database</a></li>
<li><a href="#4">Download Code</a></li>
<li><a href="#5">Summary</a></li>
</ol>
<p><a name="1"></a></p>
<h3>Declare a Connection String</h3>
<p>If you continue from the previous part, you simply move the <strong>connStr</strong> variable from TestConnection() method to global scope. Otherwise, declare a new global variable as connection string with the value below.<br />
<em><strong>Note:</strong></em> For more detail about how to build a connection string, see the previous post.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Private</span> connStr <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> = <span style="color: #800000;">&quot;Database=world;&quot;</span> &amp; _
                    <span style="color: #800000;">&quot;Data Source=192.168.125.21;&quot;</span> &amp; _
                    <span style="color: #800000;">&quot;User Id=worldUser;Password=worldpassword;&quot;</span> &amp; _
                    <span style="color: #800000;">&quot;Connection Timeout=20&quot;</span></pre></td></tr></table></div>

<p>The code will look similar as the figure below.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/_1.png" width="250" height="184" alt="MySQL Connection String" title="MySQL Connection String"  /></a><br />
<a href="#top">Back to top</a></p>
<p><a name="2"></a></p>
<h3>Retrieve data from database</h3>
<p>To retrieve data from MySQL, I&#8217;ll use <strong>MySqlDataReader</strong> Class from MySql.Data library. First, I open the connection to the world database on MySQL Server. Then, executes the query command by using ExecuteReader method and assigns to MySqlDataReader object. After that, looping on MySqlDataReader object to get result. Let&#8217;s see the code below.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Public</span> <span style="color: #000080;">Sub</span> retriveData()
        Try
            <span style="color: #000080;">Dim</span> query <span style="color: #000080;">As</span> <span style="color: #000080;">String</span> = <span style="color: #800000;">&quot;SELECT * FROM Country&quot;</span>
            <span style="color: #000080;">Dim</span> connection <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> MySqlConnection(connStr)
            <span style="color: #000080;">Dim</span> cmd <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> MySqlCommand(query, connection)
&nbsp;
            connection.<span style="color: #000080;">Open</span>()
&nbsp;
            <span style="color: #000080;">Dim</span> reader <span style="color: #000080;">As</span> MySqlDataReader
            reader = cmd.ExecuteReader()
&nbsp;
            <span style="color: #000080;">While</span> reader.Read()
                Console.WriteLine((reader.GetString(0) &amp; <span style="color: #800000;">&quot;, &quot;</span> &amp; _
                    reader.GetString(1)))
            <span style="color: #000080;">End</span> <span style="color: #000080;">While</span>
&nbsp;
            reader.<span style="color: #000080;">Close</span>()
            connection.<span style="color: #000080;">Close</span>()
        Catch ex <span style="color: #000080;">As</span> Exception
            Console.WriteLine(ex.Message)
        <span style="color: #000080;">End</span> Try
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></td></tr></table></div>

<p><em><strong>Code Explanation:</strong></em></p>
<ul>
<li>Line 21: Create a query variable as string.</li>
<li>Line 22: Create a MySQLConnection object with the defined connection string in global as parameter.</li>
<li>Line 23: Create a MySQLCommand object with previous 2 variables as parameters.</li>
<li>Line 25: Open a connection to MySQL Server using the defined connection string.</li>
<li>Line 27-28: Call ExecuteReader() method and assign the result to MySqlDataReader<br />
 object.</li>
<li>Line 30-33: Looping on MySqlDataReader object to get results to the console.</li>
<li>Line 35-36: Close the reader and connection. I <strong>recommend</strong> to close these objects after using everytime.</li>
<li>Line 38: If there is any error in the method, send to console.</li>
</ul>
<p>The code will look similar as the figure below.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/_2.png" width="250" height="219" alt="Code for Retrieve Data from MySQL" title="Code for Retrieve Data from MySQL"  /></a></p>
<p>The result of the query shows the first and second columns in the output window.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/_3.png" width="250" height="95" alt="SELECT Result" title="SELECT Result"  /></a><br />
<a href="#top">Back to top</a></p>
<p><a name="3"></a></p>
<h3>Update Record on Database</h3>
<p>Coding on INSERT, UPDATE and DELETE SQL operations are identical except only sql command that is executed. When I perform these operations to database, there is no need to get records from the database. So I use <strong>ExecuteNonQuery()</strong> Method from <strong>MySqlCommand</strong> Class. For INSERT, UPDATE and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.<br />
<em><strong>Note: </strong></em>You can use ExecuteNonQuery to perform any type of database operation, however any result sets returned will not be available.</p>
<h4>Update Function</h4>
<p>This function accepts a parameter as sql command and send to execute on MySQL Server. So the function can be use for INSERT, UPDATE and DELETE operations also any operation that doesn&#8217;t need a return result sets. Also, it returns an integer value of affected rows.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #000080;">Function</span> updateRecord(<span style="color: #000080;">ByVal</span> query <span style="color: #000080;">As</span> <span style="color: #000080;">String</span>) <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span>
        Try
            <span style="color: #000080;">Dim</span> rowsEffected <span style="color: #000080;">As</span> <span style="color: #000080;">Integer</span> = 0
            <span style="color: #000080;">Dim</span> connection <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> MySqlConnection(connStr)
            <span style="color: #000080;">Dim</span> cmd <span style="color: #000080;">As</span> <span style="color: #000080;">New</span> MySqlCommand(query, connection)
&nbsp;
            connection.<span style="color: #000080;">Open</span>()
&nbsp;
            rowsEffected = cmd.ExecuteNonQuery()
&nbsp;
            connection.<span style="color: #000080;">Close</span>()
&nbsp;
            Return rowsEffected
        Catch ex <span style="color: #000080;">As</span> Exception
            Console.WriteLine(ex.Message)
        <span style="color: #000080;">End</span> Try
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></td></tr></table></div>

<p><em><strong>Code Explanation:</strong></em></p>
<ul>
<li>Line 50: The code is similar to retrieve data section only it call ExecuteNonQuery() method and the return value is affected rows.</li>
</ul>
<p>The function code will look similar as the figure below.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/_4.png" width="250" height="177" alt="Code for Update Record" title="Code for Update Record"  /></a></p>
<h4>Example INSERT</h4>
<p>To execute INSERT command, try the statement below. The sql command will insert a new record to <strong>Country</strong> table on <strong>world</strong> database. Then, output the affected rows to console.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">Console.WriteLine(updateRecord(<span style="color: #800000;">&quot;INSERT INTO Country (Code, Name) VALUES ('AAA','Test Name')&quot;</span>))</pre></td></tr></table></div>

<h4>Example UPDATE</h4>
<p>The UPDATE command belows change Name to <strong>&#8216;Test2&#8242;</strong> on row which has code = <strong>&#8216;AAA&#8217;</strong>. And output the affected rows to console.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>15
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">Console.WriteLine(updateRecord(<span style="color: #800000;">&quot;UPDATE Country SET Name='Test2' WHERE Code ='AAA'&quot;</span>))</pre></td></tr></table></div>

<h4>Example DELETE</h4>
<p>The DELETE command deletes a record which has code equals <strong>&#8216;AAA&#8217;</strong>. And output the affected rows to console.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>16
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">Console.WriteLine(updateRecord(<span style="color: #800000;">&quot;DELETE FROM Country WHERE Code ='AAA'&quot;</span>))</pre></td></tr></table></div>

<p>When I have run the application with the 3 statements above, the output window shows the row affected of each statement as the figure below.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part7/_5.png" width="250" height="87" alt="Row Affected" title="Row Affected"  /></a><br />
<a href="#top">Back to top</a></p>
<p><a name="4"></a></p>
<h3>Download Code</h3>
<p>You can download a complete project file at here &#8211; <strong><a href="http://www.linglom.com/downloads/SampleMySQL.zip">SampleMySQL</a></strong> (zip format). The project was created on Microsoft Visual Studio 2005.<br />
<a href="#top">Back to top</a></p>
<p><a name="5"></a></p>
<h3>Summary</h3>
<p>Now you have reach the end of the article. After 7 parts, you should be able to develop an simple application to access MySQL Server on your own. I think that the article is quite clear than other accessing database server articles that I wrote last year. If you have any question, feel free to leave a comment below.<br />
<a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2008/01/16/accessing-mysql-on-netbeans-using-jdbc-part-ii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations'>Accessing MySQL on NetBeans using JDBC, Part II: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2007/07/14/accessing-sql-server-on-netbeans-using-jdbc-part-ii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations'>Accessing SQL Server on NetBeans using JDBC, Part II: Perform SQL Operations</a></li>
<li><a href='http://www.linglom.com/2009/09/07/accessing-ms-access-2007-on-netbeans-6-5-using-jdbc-part-4-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations'>Accessing MS Access 2007 on NetBeans 6.5 using JDBC, Part 4: Perform SQL Operations</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection</title>
		<link>http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/</link>
		<comments>http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 14:40:59 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=584</guid>
		<description><![CDATA[Create Connection After I have prepared many things for showing how to access MySQL Server using VB.NET. Let&#8217;s see what I have done so far. Right now, I have a remote MySQL Server at 192.168.125.21 with port 3306 (Default port). Also, a sample database &#8220;world&#8221; and a user account &#8220;worldUser&#8221; with password &#8220;worldpassword&#8221;. Now it&#8217;s [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2007/12/05/accessing-mysql-on-netbeans-using-jdbc-part-i-create-a-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on NetBeans using JDBC, Part I: Create a connection'>Accessing MySQL on NetBeans using JDBC, Part I: Create a connection</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><h3>Create Connection</h3>
<p>After I have prepared many things for showing how to access MySQL Server using VB.NET. Let&#8217;s see what I have done so far. Right now, I have a remote MySQL Server at 192.168.125.21 with port 3306 (Default port). Also, a sample database <strong>&#8220;world&#8221;</strong> and a user account <strong>&#8220;worldUser&#8221;</strong> with password <strong>&#8220;worldpassword&#8221;</strong>. Now it&#8217;s time to start Microsoft Visual Studio 2005 on a development PC.</p>
<p><span id="more-584"></span></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><!--adsense#Square--></p>
<h3>Create Connection</h3>
<ol>
<li>On Development PC, open Microsoft Visual Studio 2005.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_1.png" width="250" height="213" alt="Open Microsoft Visual Studio 2005" title="Open Microsoft Visual Studio 2005"  /></a></li>
<li>Create a New Windows Application Project <strong>&#8220;SampleMySQL&#8221;</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_2.png" width="250" height="170" alt="New Windows Application" title="New Windows Application"  /></a></li>
<li>First, I need to add a MySQL library. Right-click on the project name (<strong>SampleMySQL</strong>) -> <strong>Add Reference</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_3.png" width="250" height="213" alt="Add Reference" title="Add Reference"  /></a></li>
<li>On Add Reference, select <strong>MySQL.Data</strong> on .NET tab.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_4.png" width="250" height="201" alt="MySQL.Data" title="MySQL.Data"  /></a></li>
<li>By default, the reference library (<strong>MySQL.Data</strong>) won&#8217;t be copied to the output directory. That means when you deploy the application on other PC which doesn&#8217;t have the library installed, it&#8217;ll throw error. So I have to set the <strong>Copy Local</strong> property of the library file to <strong>True</strong>. Click <strong>Show All Files</strong> icon.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_5.png" width="250" height="213" alt="Show All Files" title="Show All Files"  /></a></li>
<li>Expand <strong>References</strong> -> Select <strong>MySQL.Data</strong> -> Change <strong>Copy Local</strong> property to True.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_6.png" width="250" height="213" alt="Set Copy Local to True" title="Set Copy Local to True"  /></a></li>
<li>Now it&#8217;s time to coding the application. First, I have to import a namespace. Open the Code View and add this line on the top.

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">Imports MySql.Data.MySqlClient</pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/7.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_7.png" width="250" height="192" alt="Imports MySql.Data" title="Imports MySql.Data"  /></a></li>
<li>Add these code to the Class.

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Form1_Load<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, _
            <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> <span style="color: #FF8000;">MyBase</span>.<span style="color: #0000FF;">Load</span>
        TestConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Sub</span> TestConnection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Try</span>
            <span style="color: #0600FF;">Dim</span> connStr <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Database=world;&quot;</span> <span style="color: #008000;">&amp;</span> _
                    <span style="color: #808080;">&quot;Data Source=192.168.125.21;&quot;</span> <span style="color: #008000;">&amp;</span> _
                    <span style="color: #808080;">&quot;User Id=worldUser;Password=worldpassword&quot;</span>
            <span style="color: #0600FF;">Dim</span> connection <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> MySqlConnection<span style="color: #000000;">&#40;</span>connStr<span style="color: #000000;">&#41;</span>
            connection.<span style="color: #0600FF;">Open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            connection.<span style="color: #0600FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Connection is okay.&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">Catch</span> ex <span style="color: #FF8000;">As</span> Exception
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Message</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Try</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><strong>Code Explanation:</strong></p>
<ul>
<li>Line 1-4: Simple Form_Load event that call TestConnection() method. The method is invoked when the form is loaded.</li>
<li>Line: 7-17: Try-Catch scope. If there is any error in try scope, throws exception and goes to catch scope.</li>
<li>Line: 8-10: A connection string represents configuration for connect to MySQL Server. Common attributes are:
<ol>
<li><strong>Database</strong>. The database to be used after a connection is opened.</li>
<li><strong>Data Source</strong>. The name of the MySQL server to which to connect.</li>
<li><strong>Port</strong>. The port MySQL is using to listen for connections. The default value is 3306</li>
<li><strong>User ID</strong>. The user that use to connect to the database on MySQL Server </li>
<li><strong>Password</strong>. Password of the user.</li>
<li><strong>Connection Timeout</strong>. Time to wait while trying to establish a connection before terminating the attempt and generating an error.
</li>
</ol>
</li>
<li>Line 11: Create MySqlConnection object and assign connectionString property.</li>
<li>Line 12-13: Test open and close the connection to the database on MySQL Server.</li>
<li>Line 14: If there is no error, show a success message.</li>
<li>Line 16: Show the error message.</li>
</ul>
</li>
<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/8.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_8.png" width="250" height="184" alt="" title=""  /></a></p>
<li>Next, test the code by run the application. If the connection is successfully connected and disconnected. You&#8217;ll see the message <strong>&#8220;Connection is okay&#8221;</strong>.<br />
<img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/9.png" width="122" height="100" alt="Successfully Connected" title="Successfully Connected" /></li>
<li>If something wrongs, you&#8217;ll see message other than the previous step. The figure below is the example that mistyped the database name in the connection string.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/10.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part6/_10.png" width="250" height="79" alt="Unsuccessful Connection" title="Unsuccessful Connection"  /></a></li>
</ol>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2007/12/05/accessing-mysql-on-netbeans-using-jdbc-part-i-create-a-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on NetBeans using JDBC, Part I: Create a connection'>Accessing MySQL on NetBeans using JDBC, Part I: Create a connection</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</title>
		<link>http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/</link>
		<comments>http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 03:00:47 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=581</guid>
		<description><![CDATA[Install MySQL Connector Net From last 4 parts, I have prepared MySQL Server with sample database. I&#8217;ve done on a database PC. Next, I&#8217;ll move to a development PC. Assume that I have already installed Microsoft Visual Studio 2005 already. Now I need to download and install MySQL Connector/Net 5.2 on a Development PC which [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database</a></li>
<li><a href='http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></li>
<li><a href='http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p><a name="top"></a></p>
<h3>Install MySQL Connector Net</h3>
<p>From last 4 parts, I have prepared MySQL Server with sample database. I&#8217;ve done on a database PC. Next, I&#8217;ll move to a development PC. Assume that I have already installed Microsoft Visual Studio 2005 already. Now I need to download and install MySQL Connector/Net 5.2 on a Development PC which is a library for connect to MySQL Server from .NET Application.</p>
<p><span id="more-581"></span></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><!--adsense#Square--></p>
<h3>Setup MySQL Connector Net 5.2.5</h3>
<ol>
<li>Download <a href="http://dev.mysql.com/downloads/connector/net/5.2.html" rel="nofollow" target="_blank">MySQL Connector/Net 5.2</a> from mysql.com.</li>
<li>Extract the downloaded file <strong>&#8220;mysql-connector-net-5.2.5.zip&#8221;</strong> on a Development PC.</li>
<li>Execute the downloaded file <strong>&#8220;MySql.Data.msi&#8221;</strong>. On Setup Welcome Screen, click <strong>Next</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_1.png" width="250" height="193" alt="Execute MySql.Data.msi" title="Execute MySql.Data.msi"  /></a></li>
<li>On Choose Setup Type, click on <strong>Typical</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_2.png" width="250" height="193" alt="Choose Typical Installation" title="Choose Typical Installation"  /></a></li>
<li>On Ready to install MySQL Connector Net 5.2.5, click <strong>Install</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_3.png" width="250" height="193" alt="Install MySQL Connector Net 5.2.5" title="Install MySQL Connector Net 5.2.5"  /></a></li>
<li>When Setup has completed, click <strong>Finish</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_4.png" width="250" height="193" alt="Finish Setup" title="Finish Setup"  /></a></li>
<li>You can view the document of MySQL Connector Net 5.2.5 from Start -> Programs -> MySQL -> MySQL Connector Net 5.2.5 -> Documentation.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_5.png" width="250" height="107" alt="Documentation" title="Documentation"  /></a></li>
<li>This is the screen shot of documentation.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part5/_6.png" width="250" height="139" alt="Document Screen Shot" title="Document Screen Shot"  /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database</a></li>
<li><a href='http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></li>
<li><a href='http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &amp; Grant MySQL User Account</title>
		<link>http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/</link>
		<comments>http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 15:57:33 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=576</guid>
		<description><![CDATA[Create &#038; Grant MySQL User Account By default, the root account on MySQL Server has all privileges on every tables on MySQL Server but only localhost can have accessed (remote access is not allowed) and it is recommend to use other user account rather than root account to perform operations on MySQL Server (for security [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection</a></li>
<li><a href='http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server</a></li>
<li><a href='http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p><a name="top"></a></p>
<h3>Create &#038; Grant MySQL User Account</h3>
<p>By default, the root account on MySQL Server has all privileges on every tables on MySQL Server but only localhost can have accessed (remote access is not allowed) and it is recommend to use other user account rather than root account to perform operations on MySQL Server (for security issue). Therefore, you should create a new user account on MySQL and grant at least privileges for the account as possible. </p>
<p><span id="more-576"></span></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><!--adsense#Square--></p>
<p>This post, I&#8217;m going to show how to create a new user account <strong>&#8220;worldUser&#8221;</strong> on MySQL Server and grant privileges to the user account. Mostly usage privileges are SELECT, INSERT, DELETE and UPDATE. Also, I&#8217;ll allow remote connection from any host so that I can develop an application from remote PC to the database PC.<br />
<em><strong>Note:</strong></em> If you are in development in a single environment, it&#8217;s OK to use root account. But <strong>Don&#8217;t</strong> in production.</p>
<h3>Section</h3>
<ol>
<li><a href="#1">Create New MySQL User Account</a></li>
<li><a href="#2">Grant Privileges on User Account</a></li>
</ol>
<p><a name="1"></a></p>
<h3>Create New MySQL User Account</h3>
<ol>
<li>On the Database PC, connect to MySQL Server. Open Command-line and type

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mysql -u root -p</pre></div></div>

<p>It&#8217;ll ask for the password. Type root&#8217;s password.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/_1.png" width="250" height="126" alt="Connect to MySQL Server" title="Connect to MySQL Server"  /></a>
</li>
<li>To Create a User Account on MySQL Server, use this format:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">CREATE USER username IDENTIFIED BY 'password'</pre></div></div>

</li>
<li>I&#8217;ll create MySQL User Account <strong>&#8220;worldUser&#8221;</strong> with password <strong>&#8220;worldpassword&#8221;</strong>. I use this account to connect to MySQL Server from remotely PC in later post.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #000099;">USER</span> worldUser IDENTIFIED BY <span style="color: #008000;">'worldpassword'</span><span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/_2.png" width="250" height="75" alt="Create MySQL User Account" title="Create MySQL User Account"  /></a></li>
</ol>
<p><a href="#top">Back to top</a></p>
<p><a name="2"></a></p>
<h3>Grant Privileges on User Account</h3>
<ol>
<li>To grant privileges on MySQL User Account, use this format:

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">GRANT privileges ON database.table TO 'username'@'host'</pre></div></div>

</li>
<li>I&#8217;m going to grant privileges on <strong>&#8220;worldUser&#8221;</strong> to allow SELECT, INSERT, UPDATE and DELETE on <strong>world</strong> database from any machine.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">SELECT</span><span style="color: #000033;">,</span><span style="color: #990099; font-weight: bold;">INSERT</span><span style="color: #000033;">,</span><span style="color: #990099; font-weight: bold;">UPDATE</span><span style="color: #000033;">,</span><span style="color: #990099; font-weight: bold;">DELETE</span> <span style="color: #990099; font-weight: bold;">ON</span> world.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'worldUser'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span><span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/_3.png" width="250" height="27" alt="GRANT PRIVILEGES" title="GRANT PRIVILEGES"  /></a>
</li>
<li>Another grant example. Grant SELECT privilege to mysql.proc on the certain user. This is not required to run, just an example.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">GRANT</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #990099; font-weight: bold;">ON</span> mysql.proc <span style="color: #990099; font-weight: bold;">TO</span> <span style="color: #008000;">'worldUser'</span>@<span style="color: #008000;">'<span style="color: #008080; font-weight: bold;">%</span>'</span><span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part4/_4.png" width="250" height="34" alt="GRANT PRIVILEGE" title="GRANT PRIVILEGE"  /></a>
</li>
</ol>
<p><a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/03/13/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vi-create-connection/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VI: Create Connection</a></li>
<li><a href='http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server</a></li>
<li><a href='http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database</title>
		<link>http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/</link>
		<comments>http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 03:36:45 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=570</guid>
		<description><![CDATA[Install Sample Database You can download example databases for MySQL at http://dev.mysql.com/doc (Scroll down to Example Databases section). By the time I&#8217;m writing the article, there are 4 sample databases available on the page. I choose the world database since it compatible with all MySQL version. You can see index of this series at Accessing [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
<li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><p><a name="top"></a></p>
<h3>Install Sample Database</h3>
<p>You can download example databases for MySQL at http://dev.mysql.com/doc (Scroll down to <strong>Example Databases</strong> section). By the time I&#8217;m writing the article, there are 4 sample databases available on the page. I choose the <strong>world database</strong> since it compatible with all MySQL version.</p>
<p><span id="more-570"></span></p>
<p>You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><!--adsense#Square--></p>
<h3>Install Sample Database</h3>
<ol>
<li>Download the sample database <strong>&#8220;world database&#8221;</strong>. Extract it, you&#8217;ll get the <strong>world.sql</strong> file to the Database PC. This file will be imported to MySQL in few steps later.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_1.png" width="250" height="87" alt="Download Sample Database" title="Download Sample Database"  /></a></li>
<li>On the database PC, open command-line mode. Type below command to connect to the MySQL Server using MySQL&#8217;s root account.

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mysql -u root -p</pre></div></div>

<p>The parameter -p makes MySQL ask you to enter the password. Then, type the root&#8217;s password. In this example, it is <strong>&#8220;password&#8221;</strong>.<br />
<em><strong>Note: </strong></em>You can type this command on any path because I have added MySQL path to system environment while I was configuring MySQL Server on the previous part.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_2.png" width="250" height="126" alt="Connect to MySQL Server" title="Connect to MySQL Server"  /></a></li>
<li>Now I have connected to the MySQL Server. Next, I&#8217;m going to create an empty database name <strong>&#8220;world&#8221;</strong>.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DATABASE</span> world<span style="color: #000033;">;</span></pre></div></div>

<p>Then, change the default database to the created database.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">USE</span> world<span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_3.png" width="250" height="76" alt="Create A Blank Database" title="Create A Blank Database"  /></a></li>
<li>Next, load the contents of <strong>&#8220;world.sql&#8221;</strong> file into the world database. The <strong>&#8220;world.sql&#8221;</strong> file was created on the first step.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">SOURCE c:world.sql</pre></div></div>

<p>You have to alter the path to where the <strong>world.sql</strong> file is located.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_4.png" width="250" height="23" alt="Load World Content to MySQL Database" title="Load World Content to MySQL Database"  /></a></li>
<li>You&#8217;ll see lot of output that MySQL performs query from the world.sql file.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_5.png" width="250" height="126" alt="Query Output" title="Query Output"  /></a></li>
<li>After MySQL finishes processing the world.sql file, try to test if the query is executed successfully. Type the command below to list all tables on the current database.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">SHOW</span> <span style="color: #990099; font-weight: bold;">TABLES</span><span style="color: #000033;">;</span></pre></div></div>

<p>You&#8217;ll see that there are 3 tables.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_6.png" width="250" height="105" alt="Show Tables" title="Show Tables"  /></a></li>
<li>You also can see the columns on the table by type the below command.

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">DESCRIBE</span> Country<span style="color: #000033;">;</span></pre></div></div>

<p><a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/7.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part3/_7.png" width="250" height="207" alt="View Columns of Table" title="View Columns of Table"  /></a></li>
<li>If you see the columns and tables as previous steps, it means that you have install sample database successfully.</li>
</ol>
<h3>Reference</h3>
<ul>
<li><a href="http://dev.mysql.com/doc/world-setup/en/world-setup.html" rel="nofollow" target="_blank">Setting Up the world Database</a> &#8211; MySQL.com.</li>
</ul>
<p><a href="#top">Back to top</a></p>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
<li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2009/03/18/accessing-mysql-on-vbnet-using-mysql-connectornet-part-vii-perform-sql-operations/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part VII: Perform SQL Operations</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing MySQL on VB.NET using MySQL Connector/Net, Part II: Setup MySQL Server</title>
		<link>http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/</link>
		<comments>http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 14:41:41 +0000</pubDate>
		<dc:creator>linglom</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.linglom.com/?p=567</guid>
		<description><![CDATA[Setup MySQL Server This section I&#8217;ll show how to setup MySQL Server on a database PC. You can see index of this series at Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction Download MySQL 5.1.30 Community Edition from mysql.com. Double-click the setup file mysql-essential-5.1.30-win32.msi. Click Next. On Setup Type, select Typical. Click Next. [...]


Related posts:<ol><li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
<li><a href='http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<div class="KonaBody"><h3>Setup MySQL Server</h3>
<p>This section I&#8217;ll show how to setup MySQL Server on a database PC. You can see index of this series at <a href="http://www.linglom.com/2009/02/12/accessing-mysql-on-vbnet-using-mysql-connectornet-part-i-introduction/">Accessing MySQL on VB.NET using MySQL Connector/Net, Part I: Introduction</a></p>
<p><span id="more-567"></span></p>
<p><!--adsense#Square--></p>
<ol>
<li>Download MySQL 5.1.30 Community Edition from mysql.com.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/1.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_1.png" width="250" height="152" alt="mysql.com" title="mysql.com"  /></a></li>
<li>Double-click the setup file <strong>mysql-essential-5.1.30-win32.msi</strong>. Click <strong>Next</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/2.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_2.png" width="250" height="191" alt="MySQL Server Installation" title="MySQL Server Installation"  /></a></li>
<li>On Setup Type, select Typical. Click <strong>Next</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/3.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_3.png" width="250" height="191" alt="Setup Type - Typical" title="Setup Type - Typical"  /></a></li>
<li>On Ready to Install the Program, click <strong>Install</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/4.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_4.png" width="250" height="191" alt="Install MySQL Server" title="Install MySQL Server"  /></a></li>
<li>On Wizard Completed, check <strong>Configure the MySQL Server Now</strong> and click <strong>Finish</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/5.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_5.png" width="250" height="191" alt="Finishes MySQL Server Installation" title="Finishes MySQL Server Installation"  /></a></li>
<li>On MySQL Configuration Wizard, click <strong>Next</strong>.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/6.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_6.png" width="250" height="191" alt="Configure MySQL Server" title="Configure MySQL Server"  /></a></li>
<li>On MySQL Server Instance Configuration, select <strong>Standard Configuration</strong>.<br />
<em><strong>Note: </strong></em>If you want to develop in a single PC environment, you can select <strong>Detailed Configuration</strong> instead and choose <strong>Developer Machine</strong> so MySQL Server won&#8217;t consume too much resource on the PC.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/7.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_7.png" width="250" height="191" alt="Standard Configuration" title="Standard Configuration"  /></a></li>
<li>On MySQL Server Instance Configuration, verify that all check boxes are checked  on this page and click <strong>Next</strong>. The first and second (<strong>Install As Windows Service</strong> and <strong>Launch the MySQL Server automatically</strong>) check boxes configure MySQL as a Windows service so that you don&#8217;t have to login to the PC and start MySQL Server manually, it&#8217;ll start when the PC is on automatically.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/8.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_8.png" width="250" height="191" alt="Install MySQL As Windows Service" title="Install MySQL As Windows Service"  /></a></li>
<li>On MySQL Server Instance Configuration, check only the upper check box <strong>Modify Security Settings</strong> and enter the root password. The root user is the default user on MySQL who has all privileges on the MySQL Server. In this example, I set the root&#8217;s password to <strong>&#8220;password&#8221;</strong>. Click <strong>Next</strong>.<br />
<em><strong>Note:</strong></em> This is just an example, you should set password more complexity than this.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/9.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_9.png" width="250" height="191" alt="Set Root's Password" title="Set Root's Password"  /></a></li>
<li>On MySQL Server Instance Configuration, click <strong>Execute</strong> to start the configuration.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/10.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_10.png" width="250" height="191" alt="Execute MySQL Server Configuration" title="Execute MySQL Server Configuration"  /></a></li>
<li>When the configuration is done, click <strong>Finish</strong> to complete install and configure MySQL Server.<br />
<a href="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/11.png" target="_blank"><img src="http://www.linglom.com/images/Windows/Programming/VBNET-MySQL/Part2/_11.png" width="250" height="191" alt="Finishes Configure MySQL Server" title="Finishes Configure MySQL Server"  /></a></li>
</ol>
</div>

<p>Related posts:<ol><li><a href='http://www.linglom.com/2009/02/28/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iv-create-grant-mysql-user-account/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part IV: Create &#038; Grant MySQL User Account</a></li>
<li><a href='http://www.linglom.com/2009/03/06/accessing-mysql-on-vbnet-using-mysql-connectornet-part-v-install-mysql-connector-net/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part V: Install MySQL Connector Net</a></li>
<li><a href='http://www.linglom.com/2009/02/23/accessing-mysql-on-vbnet-using-mysql-connectornet-part-iii-install-sample-database/' rel='bookmark' title='Permanent Link: Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database'>Accessing MySQL on VB.NET using MySQL Connector/Net, Part III: Install Sample Database</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.linglom.com/2009/02/17/accessing-mysql-on-vbnet-using-mysql-connectornet-part-ii-setup-mysql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
