Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 8th, 2007, 01:25 AM
Registered User
 
Join Date: Feb 2007
Location: faridabad, haryana, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default visual basic 2005

I want to connect my database in ms-access to vb 2005 and also want to show the first record..can u please tell me how can i do it...


Reply With Quote
  #2 (permalink)  
Old February 9th, 2007, 09:59 PM
Registered User
 
Join Date: Feb 2007
Location: Hyderabad, Andhra Pradesh, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi nidhigupta001,

I'm a learner. The below sample code might help you in connecting Access through VB.
N regarding displaying the first record, Its all how you want to retrieve the table in the .mdb and use accordingly as the database may hold any N number of tables.
Correct me if I'm wrong.
------------------------------------
Public con As New ADODB.Connection
Public rs As New ADODB.Recordset
Private Sub ConTest_Click()
    Dim con As New ADODB.Connection
    ' rs is the record set
    Dim rs As New ADODB.Recordset
    ' the (source=) is the path of the database
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ConnectionTest\EmpInfo.mdb;Persist Security Info=False"
End Sub

Aspire Inspire Achieve
Reply With Quote
  #3 (permalink)  
Old February 11th, 2007, 04:06 PM
Authorized User
 
Join Date: Aug 2006
Location: Charlotte, NC, USA.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubisascends
Default

You can also try this:

Dim myCommand as new OledbCommand
Dim myConnection as new OledbConnection([Connection String])

myCommand.Connection = myConnection
myCommand.CommandText = [SQL string]

myCommand.Connection.Open()
myCommand.[command type]
myCommand.Connection.Close()

There are a few tricks to connecting to an Access Database. You need to know the connection string, you can locate the connection string at www.Connectionstrings.com. Older versions of Access use the Jet engine, which will need to be stated in the connection string, as nadhan_f showed in the con.Open line, while Access 07 uses a different engine.

The command text needs to show the sql string that you are going to execute (ie "Select * from sto_Employees")

The command type will tell the application what to run, some examples are:
ExecuteQuery - used for select queries
ExecuteNonQuery - used for insert, update and delete queries
ExecuteReader - used to run a data reader

What command type you use will depend on what you are trying to do.

Hope this helps.

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Albert Einstein
US (German-born) physicist (1879 - 1955)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Date in Visual Basic 2005. sheelnathkekre Visual Basic 2005 Basics 1 August 15th, 2008 09:42 AM
Visual Basic 2005 Express CForce Visual Basic 2005 Basics 1 June 22nd, 2008 10:21 PM
Lottery Program Help...I'm using 2005 Visual Basic psycoblaster VB.NET 2002/2003 Basics 13 May 23rd, 2007 09:13 PM
visual basic 2005 nidhigupta001 Visual Basic 2005 Basics 1 February 12th, 2007 08:26 AM
FTP in Visual Studio 2005 Pro (Visual Basic) shoopes VB How-To 1 June 29th, 2006 02:08 PM



All times are GMT -4. The time now is 04:57 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.