please help me out in updating a MS ACCESS database via vb.NET...I am in need of the code.Thank You

Dani AI

Generated

This thread really covers two separate problems: (A) connecting to and updating an MS Access file from VB.NET, and (B) opening the main form without terminating the app when the login form closes. The MSDN pointer from is a good starting point; the practical patterns below expand on the short form suggestions from , and and avoid common pitfalls others hit later in the thread.

A minimal, safe update pattern uses parameterized commands and disposes connections promptly. Example (accdb uses ACE; .mdb uses Jet):

Imports System.Data.OleDb

Dim connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\path\mydb.accdb;"
Using cn As New OleDbConnection(connString)
    cn.Open()
    Using cmd As New OleDbCommand("UPDATE MyTable SET FieldA = ? WHERE ID = ?", cn)
        cmd.Parameters.AddWithValue("FieldA", newValue)
        cmd.Parameters.AddWithValue("ID", idValue)
        Dim rowsAffected = cmd.ExecuteNonQuery()
    End Using
End Using

An alternate pattern is DataAdapter + DataSet + OleDbCommandBuilder when working with UI-bound datasets:

Using da As New OleDbDataAdapter("SELECT * FROM MyTable WHERE ID = ?", cn)
    da.SelectCommand.Parameters.AddWithValue("ID", idValue)
    Dim ds As New DataSet()
    da.Fill(ds, "MyTable")
    ds.Tables("MyTable").Rows(0)("FieldA") = newValue
    Dim cb As New OleDbCommandBuilder(da)
    da.Update(ds, "MyTable")
End Using

Troubleshooting notes: match provider to file type (ACE vs Jet), compile to x86 if only 32‑bit ACE is installed, ensure the .accdb/.mdb path is correct and not exclusively locked by another Access instance, and prefer explicit parameter types over AddWithValue for predictable behavior.

For the login/main form lifecycle, prefer running an application context or start the program via a Sub Main so the login isn’t the “startup form” that drives shutdown. Example pattern using an ApplicationContext (login raises an Authenticated event):

Application.Run(New AppContext())  ' AppContext manages showing login then main form

Setting the VB project’s shutdown mode to “When last form closes” or using a Sub Main + Application.Run avoids the app exiting when the login form closes. These approaches complement the hide/close/dispose hints already posted and ensure predictable lifetime and resource cleanup.

Recommended Answers

All 14 Replies

Here are some tutorials

sir,can you provide me with codin instructions and sample codes to connect and update MS ACCESS databases through VB.NET.Please its in urgent need of a project.

Member Avatar for Member #46692

You follow a set of instructions in visual studio.

It is as simple as that. Read your book.

Thanx a lot i am sure this is gonna help

Wish u success...If u need any sort of help in VB.NET, ASP.NET, JAVA SCRIPT, HTML , MATHEMATICS, ACCOUNTING...donot hasitate to contact me ...my email id is ...

or

regards
adil

sir in my application i need to close the login form and open the main form the problem i am facing is that i can open the main form but cant close the login form at the same time can you help me in this ......thank you

sir in my application i need to close the login form and open the main form the problem i am facing is that i can open the main form but cant close the login form at the same time can you help me in this ......thank you

why dont you try declaring a object for the main form and when u call the main form add this code

dim objMain as mainform(The Main forms name)

and the point where you want to close the login form

Loginform.Close or Me.close or Me.hide()

objmain.showDialog()

Hope this helps you out :)

sir it is closing all the forms or all the forms remain...don't know what to do please help me out

why dont you try declaring a object for the main form and when u call the main form add this code

dim objMain as mainform(The Main forms name)

and the point where you want to close the login form

Loginform.Close or Me.close or Me.hide()

objmain.showDialog()

Hope this helps you out :)

How can it close all your forms.. Me.Hide or Me.Close refers to your Login Form( Me-> Login Form).. Post your code and let me have a look at it :confused:

please help me out in updating a MS ACCESS database via vb.NET...I am in need of the code.Thank You

After u put the data in the DataAdapter using the Update, Insert or Delete commands, [Connection].ExecuteNonQuery will certainly update the table.

You Can Use Dispose Method

Dim Frm as new frmmain
frm.showdialog()
me.close()
me.dispose(true)

'Here Frm Main Is Main Form Name

thank you. i have finally joined the community as a begginer with a vision of being an expert within weeks. my dedication will pay. i know.

just hide the login form.. It will really close your application because you put it in as your startup gooduluck...

Try calling up the Main form before you clear all resources used by the Login form

'insert all codes including user validation 
     MainForm.Show
'Clear all login form resources
Me.Dispose
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.