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

<channel>
	<title>VB.NET Code Snippets and Tutorials</title>
	<atom:link href="http://www.vbneter.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vbneter.com</link>
	<description>Free VB.NET Code Snippets, Source Code, Articles, Examples, Tutorials and Programming Help</description>
	<lastBuildDate>Thu, 17 Sep 2009 01:37:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to remove duplicates from Generic List (Of String)</title>
		<link>http://www.vbneter.com/2009/09/how-to-remove-duplicates-from-generic-list-of-string/</link>
		<comments>http://www.vbneter.com/2009/09/how-to-remove-duplicates-from-generic-list-of-string/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 01:35:42 +0000</pubDate>
		<dc:creator>Kulrom</dc:creator>
				<category><![CDATA[Windows programming]]></category>

		<guid isPermaLink="false">http://www.vbneter.com/?p=39</guid>
		<description><![CDATA[I will show you a two ways how to clean up generic list of dupes.
Say that you have a list of Baby names like following:

Dim MyList As New List(Of String)
        MyList.Add("Simon")
        MyList.Add("Denholm")
        MyList.Add("Denis")
  [...]]]></description>
			<content:encoded><![CDATA[<p>I will show you a two ways <strong>how to clean up generic list of dupes</strong>.<br />
Say that you have a list of Baby names like following:</p>
<pre class="brush:vb.net">
Dim MyList As New List(Of String)
        MyList.Add("Simon")
        MyList.Add("Denholm")
        MyList.Add("Denis")
        MyList.Add("Deniz")
        MyList.Add("Denley")
        MyList.Add("Dennis")
        MyList.Add("Dennison")
        MyList.Add("Denton")
        MyList.Add("Denver")
        MyList.Add("Denzel")
        MyList.Add("Denzil")
        MyList.Add("Deo")
        MyList.Add("Derain")
        MyList.Add("Derby")
        MyList.Add("Derek")
        MyList.Add("Derex")
        MyList.Add("Dermot")
        MyList.Add("Derrell")
        MyList.Add("Derren")
        MyList.Add("Derrick")
        MyList.Add("Derron")
        MyList.Add("Derry")
        MyList.Add("Derward")
        MyList.Add("Derwent")
        MyList.Add("Derwin")
        MyList.Add("Derwood")
        MyList.Add("Derwyn")
        MyList.Add("Denholm")
        MyList.Add("Denley")
        MyList.Add("Derrell")
        ' the latest 3 are dupes
</pre>
<p><strong>The simplest way to remove the dupes</strong> from your list is to use the <strong>Distinct function</strong>. </p>
<pre class="brush:vb.net">
       ' very simple
        Dim UniqueValuesOne As List(Of String) = MyList.Distinct().ToList()

        ' Check the results
        For Each Str As String In UniqueValuesOne
            Console.WriteLine(Str)
        Next
</pre>
<p><strong>the another way</strong> is to not remove duplicates, but rather create a <strong>new List only containing unique elements</strong> from the original list. </p>
<pre class="brush:vb.net">
        Dim UniqueValuesTwo As New List(Of String)
        For Each str As String In MyList
            If Not UniqueValuesTwo.Contains(str) Then
                ' add unique value
                UniqueValuesTwo.Add(str)
            End If
        Next

        ' Check the results
        For Each Str As String In UniqueValuesTwo
            Console.WriteLine(Str)
        Next
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vbneter.com/2009/09/how-to-remove-duplicates-from-generic-list-of-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Count XML Nodes from VB.NET</title>
		<link>http://www.vbneter.com/2009/08/how-to-count-xml-nodes-from-vb-net/</link>
		<comments>http://www.vbneter.com/2009/08/how-to-count-xml-nodes-from-vb-net/#comments</comments>
		<pubDate>Fri, 14 Aug 2009 13:17:05 +0000</pubDate>
		<dc:creator>Kulrom</dc:creator>
				<category><![CDATA[XML Programming]]></category>

		<guid isPermaLink="false">http://www.vbneter.com/?p=28</guid>
		<description><![CDATA[This is how do you quickly count the child nodes of an XML file. Say that you have an XML data as follows:


< ?xml version="1.0" encoding="UTF-8"?>

  
    
      < title>Sql Server 2008 Query Performance ...< /title>
      978-1-4302-1902-6
    
 [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_33" class="wp-caption alignnone" style="width: 230px"><img src="http://www.vbneter.com/wp-content/uploads/2009/08/xml-data-count-child-nodes.jpg" alt="Count XML Child Nodes" title="xml-data-count-child-nodes" width="220" height="119" class="size-full wp-image-33" /><p class="wp-caption-text">Count XML Child Nodes</p></div>
<p>This is how do you quickly <strong>count the child nodes of an XML file</strong>. Say that you have an XML data as follows:<br />
<span id="more-28"></span></p>
<pre class="brush:xml">
< ?xml version="1.0" encoding="UTF-8"?>
<inventory>
  <books>
    <book>
      < title>Sql Server 2008 Query Performance ...< /title>
      <isbn>978-1-4302-1902-6</isbn>
    </book>
    <book>
      < title>Pro ASP.NET MVC Framework< /title>
      <isbn>978-1-4302-1007-8</isbn>
    </book>
  </books>
</inventory></pre>
<p>To count the book items you may use counter iterating the books/book tags but this is how do you <strong>get the total number</strong> of book <strong>nodes in only one line</strong>.</p>
<pre class="brush:vb.net">Dim document As New XmlDocument
document.Load(xmlfilepath)
Dim count As Integer = document.SelectNodes("inventory/books/book").Count</pre>
<p><strong>Enjoy!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.vbneter.com/2009/08/how-to-count-xml-nodes-from-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write to MS Access 2007 Database from VB.NET</title>
		<link>http://www.vbneter.com/2009/08/write-to-ms-access-2007-database-from-vb-net/</link>
		<comments>http://www.vbneter.com/2009/08/write-to-ms-access-2007-database-from-vb-net/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 12:45:34 +0000</pubDate>
		<dc:creator>Kulrom</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Database Programming]]></category>
		<category><![CDATA[Windows programming]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.vbneter.com/?p=15</guid>
		<description><![CDATA[This is a very short example about how to write (insert a new record) to MSAccess database from VB.NET.
I believe that the code is well commented so no additional explanation is needed. Enjoy!

    Private Sub Form1_Load(ByVal sender As System.Object, _
             [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_16" class="wp-caption alignnone" style="width: 331px"><img class="size-full wp-image-16" title="Write-To-MS-Access-2007-Database" src="http://www.vbneter.com/wp-content/uploads/2009/08/Write-To-MS-Access-2007-Database.png" alt="Write to MSAccess 2007" width="321" height="418" /><p class="wp-caption-text">Write to MSAccess 2007</p></div>
<p>This is a very short example about <strong>how to write (insert a new record) to MSAccess database from VB.NET</strong>.<br />
I believe that the code is well commented so no additional explanation is needed. Enjoy!<br />
<span id="more-15"></span></p>
<pre class="brush:vb.net">    Private Sub Form1_Load(ByVal sender As System.Object, _
                          ByVal e As System.EventArgs) Handles MyBase.Load
        ' populate the members list at startup
        PopulateMembersList()
    End Sub

    Private Sub WriteButton_Click(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs) Handles WriteButton.Click
        ' create a new oledb connection
        Dim connection As OleDb.OleDbConnection = NewConnection()
        ' create a new command objet
        Dim command As OleDb.OleDbCommand = connection.CreateCommand
        command.CommandText = "INSERT INTO Members(FirstName, LastName, NickName) " &amp; _
                              "VALUES('" &amp; Me.FirstName.Text &amp; "', " &amp; _
                              "'" &amp; Me.LastName.Text &amp; "', " &amp; _
                              "'" &amp; Me.NickName.Text &amp; "')"
        connection.Open()
        command.ExecuteNonQuery()
        connection.Close()

        ' refresh the members list
        PopulateMembersList()
    End Sub

    Private Sub PopulateMembersList()
        ' create a new oledb connection
        Dim connection As OleDb.OleDbConnection = NewConnection()
        ' create a new command objet
        Dim command As OleDb.OleDbCommand = connection.CreateCommand
        command.CommandText = "SELECT FirstName, LastName, NickName FROM Members"

        connection.Open()
        Dim reader As OleDb.OleDbDataReader = command.ExecuteReader
        Dim listitem As ListViewItem
        While reader.Read
            listitem = MembersList.Items.Add(reader("FirstName").ToString)
            listitem.SubItems.Add(reader("LastName").ToString)
            listitem.SubItems.Add(reader("NickName").ToString)
        End While
        reader.Close()
        connection.Close()
    End Sub

    Private Function NewConnection() As OleDb.OleDbConnection
        Dim connectionstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; _
        Application.StartupPath &amp; "\MembersDB.accdb;Persist Security Info=False;"
        Dim connection As New OleDb.OleDbConnection(connectionstring)
        Return connection
    End Function</pre>
<p><a title="Source Code Writing to MS Access 2007 (VB.NET)" href="http://www.vbneter.com/uploads/WriteToMsAccess.zip" target="_blank">Source Code (Visual Studio 2008 Project) &gt;&gt;&gt;</a></p>
<p>&nbsp;</p>
<p>In order to <strong>write to MS Access 2003 database from VB.NET 2005</strong> just modify the connection string:</p>
<pre class="brush:vb.net">
Private Function NewConnection() As OleDb.OleDbConnection
    Dim connectionstring As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" &#038; _
    Application.StartupPath &#038; "\MembersDB.mdb;Persist Security Info=False;"
    Dim connection As New OleDb.OleDbConnection(connectionstring)
    Return connection
End Function
</pre>
<p><a title="Source Code Writing to MS Access 2003 (VB.NET)" href="http://www.vbneter.com/uploads/WriteToMsAccess2003.zip" target="_blank">Source Code (Visual Studio 2005 Project) &gt;&gt;&gt;</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.vbneter.com/2009/08/write-to-ms-access-2007-database-from-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Drive Type in VB.NET</title>
		<link>http://www.vbneter.com/2009/07/get-drive-type-in-vb-net/</link>
		<comments>http://www.vbneter.com/2009/07/get-drive-type-in-vb-net/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 09:39:46 +0000</pubDate>
		<dc:creator>Kulrom</dc:creator>
				<category><![CDATA[Windows programming]]></category>
		<category><![CDATA[drive type]]></category>

		<guid isPermaLink="false">http://www.vbneter.com/?p=3</guid>
		<description><![CDATA[
        Dim Drives() As DriveInfo = DriveInfo.GetDrives()
        Dim Builder As New System.Text.StringBuilder

        Dim Info As DriveInfo
        For Each Info In Drives
       [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush:vb.net">
        Dim Drives() As DriveInfo = DriveInfo.GetDrives()
        Dim Builder As New System.Text.StringBuilder

        Dim Info As DriveInfo
        For Each Info In Drives
            Builder.Append("Drive name " &#038; Info.Name &#038; Environment.NewLine)
            Builder.Append("  Drive type " &#038; Info.DriveType.ToString &#038; Environment.NewLine)
            'Check the IsReady property to see if a drive is ready
            If Info.IsReady = True Then
                Builder.Append("  Drive format " &#038; Info.DriveFormat &#038; Environment.NewLine)
            End If
        Next
        Array.Clear(Drives, 0, Drives.Length)

        MessageBox.Show(Builder.ToString)
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.vbneter.com/2009/07/get-drive-type-in-vb-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
