How to add data in ms access 2010 using VB.net 2010http://forums.asp.net/t/1658004.aspx/1?How+to+add+data+in+ms+access+2010+using+VB+net+2010Sat, 05 Mar 2011 14:02:55 -050016580044321888http://forums.asp.net/p/1658004/4321888.aspx/1?How+to+add+data+in+ms+access+2010+using+VB+net+2010How to add data in ms access 2010 using VB.net 2010 <p>Good day, I am a little bit beginner in programming regarding database and here in asp.net.</p> <p>I am using MS Access 2010 and VB.net 2010 running in Win 7 x86 OS.</p> <p>&nbsp;</p> <p>I want to add new data in access using vb.net, pls help me with the codes..</p> <p>&nbsp;</p> <p><span style="text-decoration:underline">PROCEDURE</span>:</p> <p>&nbsp;</p> <p>I created an ms access db file with Field name Gname, Lname and age. (table name is accdb)</p> <p>While in VB.net i created 3 labelbox for Given Name, Last Name and Age.</p> <p>Then a 3 textbox for Given name, Last name and Age.</p> <p>and a button for add. (to update the DB)</p> <p>&nbsp;</p> <p>the data in textbox Given Name will be record in DB Field Gname.</p> <p>the data in textbox Last Name will be record in DB Field Lname.</p> <p>the data in textbox Age Name will be record in DB Field Age.</p> <p>&nbsp;</p> <p>Hope some one will help with the code..</p> <p>i know u have a better code than i am..</p> <p>tnx in advance..</p> <p>&nbsp;</p> <p>&nbsp;</p> 2011-02-28T07:28:28-05:004323849http://forums.asp.net/p/1658004/4323849.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>Hi</p> <p>Here is a quick tutorial - hope it is ok. </p> <p><pre class="prettyprint">Const ConnectionString As String = &quot;Driver={Microsoft Access Driver (*.mdb)};Dbq=c:\somepath\mydb.mdb;&quot; Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnInsert.Click Dim conn As OdbcConnection = New OdbcConnection(ConnectionString) Dim cmd As OdbcCommand = New OdbcCommand(&quot;INSERT INTO accdb (GName, LName, Age) VALUES (?, ?, ?)&quot;, conn) cmd.Parameters.Add(&quot;@GName&quot;, OdbcType.VarChar, 255).Value = txtGName.Text cmd.Parameters.Add(&quot;@LName&quot;, OdbcType.DateTime).Value = txtLName.Text cmd.Parameters.Add(&quot;@Age&quot;, OdbcType.VarChar, 255).Value = txtAge.Text Try conn.Open() cmd.ExecuteNonQuery() Catch ex As OdbcException Throw ex Finally conn.Close() End Try End Sub</pre> </p> <p>Let me know if you run into any problems. Sorry have not tested it.</p> <p>Regards</p> <p>David</p> <p>&nbsp;</p> 2011-03-01T10:24:34-05:004328508http://forums.asp.net/p/1658004/4328508.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>Good Day Sir David;</p> <p>Thanks for your help.</p> <p>&nbsp;</p> <p>Ive try the code but it gives me an error.</p> <p>The error occurs after the catch ex..</p> <p>and i want to ask if what was the ? mark means in the codes..</p> <p>should i leave it as is or i must enter a value??.</p> <p>&nbsp;</p> <p>thanks..</p> <p>&nbsp;</p> <p>Cyril..</p> 2011-03-03T23:49:07-05:004328988http://forums.asp.net/p/1658004/4328988.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>Hi</p> <p>Sorry been on a training course for two days. What is the error? Have you set the connection string properly? Also, the &quot;?&quot; are the positional parameters for the query i.e. the values for GName, LName and Age. Leave these as is.</p> <p>If you move to SQL for example, these would become named parameters e.g. @GName, @LName, @Age</p> <p>Can you post of code as you have it. Thanks</p> <p>David</p> 2011-03-04T08:15:47-05:004329023http://forums.asp.net/p/1658004/4329023.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>When connecting to an Access database, you should better uses OLEDB instead of ODBC. But when using Access 2010 (or 2007), when you move your code to a production server (most likely a shared host?), you could run into a problem because of missing drivers. So it's better to using MDB files, which you can create using Access 2010 also.</p> <p>For code examples, read:</p> <p><a href="http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET">http://www.mikesdotnetting.com/Article/78/AccessDataSource-SqlDataSource-and-connecting-to-Access-databases-in-ASP.NET</a><br> <a href="http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access">http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access</a><br> <a href="http://www.mikesdotnetting.com/Article/76/80040E14-MS-Access-Syntax-Error-messages">http://www.mikesdotnetting.com/Article/76/80040E14-MS-Access-Syntax-Error-messages</a></p> <p>But when using VB.NET 2010 (.NET 4.0), there's a much better alternative:</p> <p><a href="http://blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/microsoft-sql-server-compact-4-0-is-available-for-download.aspx">http://blogs.msdn.com/b/sqlservercompact/archive/2011/01/12/microsoft-sql-server-compact-4-0-is-available-for-download.aspx</a></p> 2011-03-04T09:13:55-05:004330248http://forums.asp.net/p/1658004/4330248.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>Good Day..</p> <p>Got the answer im looking for</p> <p>_______________________________________________________________________________________________________________________________</p> <p>&nbsp;</p> <p>Imports System.Data.OleDb</p> <p>Public Class Form1</p> <p>&nbsp;&nbsp; &nbsp;Private Sub addbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addbtn.Click</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Dim connection As OleDb.OleDbConnection</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Dim mydb, mystr As String</p> <p>&nbsp;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mystr = (&quot;Provider=Microsoft.JET.OLEDB.4.0;&quot; &amp; _</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;Data Source=..\useracc.mdb&quot;)</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connection = New OleDb.OleDbConnection(mystr)</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;connection.Open()</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;mydb = &quot;INSERT INTO accdb (Uname,UPassword) values ('&quot; &amp; idtext.Text &amp; &quot;','&quot; &amp; passtext.Text &amp; &quot;')&quot;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Dim run = New OleDb.OleDbCommand</p> <p>&nbsp;</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Try</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;run = New OleDbCommand(mydb, connection)</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;run.ExecuteNonQuery()</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MsgBox(&quot;connection opened&quot;)</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Catch ex As Exception</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MsgBox(ex.Message, MsgBoxStyle.Critical, &quot;Oledb Error&quot;)</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;End Try</p> <p>&nbsp;&nbsp; &nbsp;End Sub</p> <p>End Class</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>____________________________________________________________________________________________________</p> <p>&nbsp;</p> <p>The error was answered..due to name reserved keyword by ms access....tnx alot</p> <p>Used software:</p> <p>*MS access 2010</p> <p>*VB.Net 2010</p> <p>*Win 7 x86 OS</p> <p>&nbsp;</p> 2011-03-05T09:59:13-05:004330289http://forums.asp.net/p/1658004/4330289.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p></p> <blockquote><span class="icon-blockquote"></span> <h4>PhapaCY</h4> Answer was error because of reserved keyword</blockquote> <p></p> <p>Most likely the reserved Word was &quot;Password&quot;. But in your original question, you were talking about totally different fieldnames! Also you were&nbsp;talking about Access 2010, and now your using a mdb file. </p> <p>And although you may think this works, it is very bad practice, because it is vulnarable to SQL Injections. I already gave you a link that explains this and how to avoid it:</p> <p><a href="http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access">http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access</a></p> <p>In this article, you also see a better syntax to use, because in your example you don't close the connection which eventually will cause problems when using Access....</p> <p>An example of a simple login system can be found here:</p> <p><a href="http://www.mikesdotnetting.com/Article/75/Simple-Login-and-Redirect-for-ASP.NET-and-Access">http://www.mikesdotnetting.com/Article/75/Simple-Login-and-Redirect-for-ASP.NET-and-Access</a></p> <p>But instead of reinventing the wheel. you could also use the build in membership. role and profile&nbsp;providers&nbsp;with Access ( or any other database):</p> <p><a href="http://imar.spaanjaars.com/404/using-the-microsoft-access-providers-to-replace-the-built-in-sql-server-providers">http://imar.spaanjaars.com/404/using-the-microsoft-access-providers-to-replace-the-built-in-sql-server-providers</a><br> <a href="http://imar.spaanjaars.com/560/using-the-microsoft-access-providers-for-membership-roles-and-profile-under-aspnet-4">http://imar.spaanjaars.com/560/using-the-microsoft-access-providers-for-membership-roles-and-profile-under-aspnet-4</a></p> <p>But I really think you should consider to use SQL Server Compact 4.0 instead</p> 2011-03-05T11:08:18-05:004330372http://forums.asp.net/p/1658004/4330372.aspx/1?Re+How+to+add+data+in+ms+access+2010+using+VB+net+2010Re: How to add data in ms access 2010 using VB.net 2010 <p>Thank you for the links...well actually what really happen was..</p> <p>i was looking for a good code in which i can understand easily for a beginner..then Mr. David gave me a code and i try it...</p> <p>then i look for some tutorials...then found the oledb and also try it..then it works for me...</p> <p>I have a little bit long term self project that i was working on...</p> <p>and as i can see theres a lot of people who can help me...tnx alot..</p> <p>ill post again if i have questions...tnx...</p> <p>&nbsp;</p> <p>God Bless</p> 2011-03-05T14:02:55-05:00