How to Add/Update/Delete Record using MS Access Database

Submitted by: 
Visitors have accessed this post 365771 times.

The primary purpose of this code is to teach beginner programmer to familiarize the concept of database programming.

This is particularly for beginner but may also applicable for intermediate programmer.


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

When i open there is no data, i cant add data also...There is no data connection, do i have to make one first?...i am using vb 2010 express.....

i have implement my system using Ms acceess 2003.
Now i have a problem with button.
I have created one button that name SAVE button..i want this button have two function wich is it can ADD/DELETE at two different table.

Can u help me??
Plese give a response at my email

[email protected]

pls sir i really need your help, i need a code that can save data and image from vb.net 2010 to Microsoft access 2003....can u mail it to my box at [email protected]

i don know the code insert n delete in database M.Eccess 2007 using button combo box..and arrage the list of combobox follow by alphabet...can 2 help me

Hi,
I am a beginner (vb.net programmer). I have ms access database with 2 tables. I connect to the database successfully but I want the primary key (Auto number) in table two to automatically appear in Foreign Key (Number) in table one after setting up the relationship.
Please I need your help.

[email protected]

Thanks in advance.

hi,

I am a start with vb.net. i have one table in Ms Access 2003 location is drive c:
but I am unknown about insert data from vb.net to Ms Access 2003.

Please, Can you tell me about this code?

[email protected]

Thank you!

go to Data then
"addnewdatasource" just click Next the default is database then
then after you click Next click on new connection and
click Change and choose this "Microsoft Access Database File (OLE DB)" then
test connection, if its successful your doing right then click OK
note: if theres a messagebox appear during this just click No. as i say No if you dont want to get error..
click Next
now after next choose your database objects... and click Finish..
go to Data again and click show datasource..
u can click and drag the data to forms...
just check to properties to datasources... hope it helps...

Try this code out, hope it helps:

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\dercio.mnisi\Desktop\Samito.mdb"

Dim OleDBConne1 As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(connString)
OleDBConne1.Open()`

Dim SQLString As String = "INSERT INTO Customer(customer_First_Names,customer_Surname,customer_Cell)VALUES('" & firstNames & "','" & surnames & "','" & cellNum & "')"

Write in Form:-

Imports System.Data.OleDb
Public Class form1
Dim v1 As New Class1(Application.StartupPath)
Dim ds As New DataSet

Private Sub btninsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninsert.Click

v1.ExecCommand("insert into tablename values("Textbox1.Text"','" + Textbox2.Text + "')")
MsgBox("Insert Successfully")
End Sub

Write in Class:-

Imports System.Data.OleDb
Public Class Class1
Dim cn As OleDbConnection
Dim cm As OleDbCommand
Dim da As OleDbDataAdapter
Dim ds As DataSet
Public vfrm As New FrmRecord

Public Sub New(ByVal path As String)
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\Database.mdb(Table name which is in ms-access")
End Sub

Public Function GetDataSet(ByVal qry As String) As DataSet
cm = New OleDbCommand(qry, cn)
da = New OleDbDataAdapter(cm)
ds = New DataSet
da.Fill(ds)
Return ds
End Function

please can you help me with vb.net code to add text and picture from vb. to access...please can mail me at [email protected]

when ever i update my record it updtae only one record. if i add no-1 and then no-2. so in my view report only 2 will show 1 will delete , why its is happening

Hi,
I am using msaccess 2003 as backend in project.
The code is just saving data which newly added but I want to update existing record of database using bindingnavigator. The code is throwing exception.
Please help me as soon as possible since the date of my project submission is coming nearer.

Thanks
[email protected]

cant see no codes here although i clicked to download them

i hpe yor code will help me in mine...:)

I need more codess....

i face a problem saving password to Access.
it work nicely if i remove password.
the error occur on INSERT and UPDATE query.
please help.
using OleDb..
i can c the password value from the sqlcommand, but it just pop up the error message.

im beginner in VB...
after enter the input data, i tried to save in .dat file...but not sure how to write it on using vb2008...
and how to call back that file?
thank you

[email protected]

sir please can you send me the SQL Server Example of the Same.
BackEnd :SQL DataBase
FrontEnd :VB.NET

My mail ID is : [email protected]

..plz post the step by step on how to add/update/and delete the record using ms access..tnx...i will wait for the response...Godbless....!!!

Hi,

I'm beginner of VB.NET. Pls help me about the database connection using vb.net with sql server,ms access and oracle with step by step process with screen shot. pls pls pls...........

My mail ID is:[email protected]

Could you please help me i used all types of memory stream code
i have an error parameter in not valid;
here is my code

  1. OleDbCommand cmd = new OleDbCommand("SELECT photo FROM stdetails where stuid='" + txtstid.Text + "'", conn);
  2.  
  3. DataSet ds = new DataSet();
  4. OleDbDataAdapter da = new OleDbDataAdapter(cmd);
  5. da.Fill(ds, "stdetails");
  6. byte[] content = (byte[])ds.Tables[0].Rows[0]["photo"];
  7.  
  8. try
  9. {
  10.  
  11. MemoryStream stream = new MemoryStream(content,true);
  12.  
  13. // i have problem in this place
  14. pictureBox2.Image = Image.FromStream(stream,true,true);
  15.  
  16. }
  17.  
  18. catch (Exception ex)
  19. {
  20.  
  21. MessageBox.Show(ex.Message.ToString());
  22.  
  23. MessageBox.Show(ex.StackTrace.ToString());
  24.  
  25. }

plz give fast solution of the above problem

how we can use " insert command " in vb ?
pls send me some examples which describe the code

hi please send me this software with frontend vb.net and backend access

thank you>>>>>>>>>>>>>>>

Hi ... Thanks for the example,but Could you please provid the same example using SQL?

Yes sure. It needs some little work to convert this to SQL Server.

Thanks bro.. Hop that you could provid us the same example with SQL server .. it will be good upportunety for us t learn from you... Thanks again...

i want 2 move data without using binding navigator in vb.net but i want to use buttons like first, previous, last & next. please help me!!!

Added to my todo list.

Plz help in creating database by code
my email id [email protected]
Praveen

hy i wanted to add images in the ms access 2003, but i forgot how the step is.could u please tell me how?

If you mean saving an image in an access table then it is automatic. You can use ole object as the data type.

Nice Sample...
I got a challenge for you...

ListView Groups...
Group the list according to the Header Collumns that is being clicked.

i dont know how to insert record in access database. i have a formCustomer to that has txtLastName, txtFirstName and txtContact.. when i click the add button it should add the record in the database then i should view the list in the main form.. your code is quite hard to understand because im only a beginner. and is it ok to insert the record from 1 form to another or there are codes needed so that i can access it to the other form.?

here is my code.

Private Sub btnAccept_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAccept.Click
Dim con As New OleDb.OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\YayaDB.mdb"
con.Open()
Dim query = "INSERT INTO Customer(Last Name,First Name, Contact No) VALUES(@LastName, @FirstName, @Contact)"
Dim cmd = New OleDbCommand(query, con)
cmd.Connection = con

cmd.Parameters.AddWithValue("@LastName", txtLastName.Text)
cmd.Parameters.AddWithValue("@FirstName", txtFirstName.Text)
cmd.Parameters.AddWithValue("@Contact", txtContactNo.Text)
cmd.ExecuteNonQuery()

con.Close()

Me.Close()

End Sub

Am new in .net and programming as well, i would like you help me save into and retrieve picture from the datebase.thank you.

If you follow the on Database Programming Made Easy you will learn how easy it is to insert data into an MS Access database.

hi,, i copied your code about how to add update delete,,, the one thats above,,,, after ive done everything already (including the module, forms, designs, everything) it shows an error "Error while trying to run your project. could not load file or assembly 'add,deletewithaccess' or one of its dependencies. the given assembly name or code was invalid. (exception from HRESULT:0x80131047)" by the way 'add,deletewithaccess' is the filename of the project i saved in... please help....

This is a strange error. May I know what version of VB.NET you are using?

hi
i am already design the code using vb.net 2005 for insert data in the table ,
but when i am again run that program then all the previous value of the table will delete and again newly entry value are store in table
my code:
Imports System.Data.OleDb

Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\raghu1stdb.mdb")

'Dim da As OleDbDataAdapter
Dim da As New OleDbDataAdapter("select * from table1", con)
'Dim x As String = "select *from table1"
' da = New OleDbDataAdapter(x, con)
Dim ds As New DataSet, dt As New DataTable, dr As DataRow
Dim i As Integer
Dim bm As BindingManagerBase : Dim cb As OleDbCommandBuilder
Dim cm As OleDbCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim x As String = "select *from table1 "
da = New OleDbDataAdapter
da.SelectCommand = New OleDbCommand(x, con)

da = New OleDbDataAdapter(x, con)
ds = New DataSet
da.Fill(ds, "name1")
dt = ds.Tables("name1")
dr = dt.NewRow
bm = Me.BindingContext(dt)
cb = New OleDbCommandBuilder(da)
''MessageBox.Show()
End Sub

Private Sub Bsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsave.Click
dr = dt.NewRow
dr.Item("ID") = Txtid.Text
dr.Item("Name") = txtname.Text
dr.Item("Address") = txtadd.Text
da.Fill(ds, "name1")
dt = ds.Tables("name1")
dt.Rows.Add(dr)

dt.AcceptChanges()
da.Update(dt)
MessageBox.Show("datais update")
End Sub

End Class

so what i will do
plz send the code for save in db using vb.net
as soon as posible plz send me i need that
plz send in my mail id: [email protected]l.com

Kindly download one of the code in Database Programming Made Easy.

I have already done this.

sir..gud am...can u teach me the hard coding connection of my project to ms access as my back end with out using any control...purely coding???...adding record in table updating retrieving and deleting...thx in advance...

i have two tables using acces database and i need to insert the same records in that two particular tables.The problem is that, "I can only save the records into one table and the other table is empty.".I hope you can help me with this particular problem, i'll apreciated it so much..thank you..

if its ok, heres my eadd: [email protected]

gives use some snapshot of you work.

Gud day sir!

i want to seek help on how to change the datasource of a report in the choice of the user dynamically..

in short.. one report viewer, multiple rdlc files can be shown simultaneously.. hust a sample code..

hope for your kind help! more power and godbless!

tnx..
aguirre

Hi friend i already download your Code.
But i want to clear that can i able to access Msdatabase File from web server.
if possible please explain me

my id is [email protected]

Are you planning to create a website using ms access database? Yes this is possible to access ms database from your web server.

Pages

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.