<?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 &#187; Database Programming</title>
	<atom:link href="http://www.vbneter.com/category/database-programming/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>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>
	</channel>
</rss>
