Login form contain two nos.of textbox anb one no.button How to connect VB.net2008 with MS-Access-2007.

Login form contain two nos.of textbox anb one no.button How to connect VB.net2008 with MS-Access-2007.

you add a module to your project then paste the following code.make sure to highlight this default code
module module1

End module
and you replace it.

Imports System.Data
Imports System.Data.OleDb
Imports System.Console
Imports System.Data.OleDb.OleDbDataReader

Module Module1
Public Sub Database_connection()
Try
Cnn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;" & "Data Source=" & Application.StartupPath & "\databasename.mdb"
Cnn.Open()
Com.Connection = Cnn
Com.CommandType = CommandType.Text
Catch ex As Exception
MsgBox(ex.Message)
End Try
'make sure you have your database in the bin folder onside your project.
End Sub

Public Sub closeconnection()
Cnn.Close()
End Sub
End Module

You don't mind to change anything.then you call the function Database_connection()
either on form load.e.g(you double click the form then type Database_connection(.)

I hope this will help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.