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

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

Submitted byAnonymous (not verified)on Sun, 01/29/2012 - 19:54

Dear Admin, i copied ur code for adding record in database. i've a strange situation, the code works fine, and i've no eny errors but as i run my app and add new record. i've no any error but for checking my record i open my table, i dont see my record. where i can b wrong? heres my code
  1. Private Sub NewPasswordTextBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewPasswordTextBox.Enter
  2. OleDbConnection1.Open()
  3. cb = New OleDbCommand("select * from Administrator", OleDbConnection1)
  4. dr = cb.ExecuteReader()
  5. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  6. If OldPasswordTextBox.Text.Equals(NewPasswordTextBox.Text) Then
  7. If OldPassword.Text.Equals("Old Password") Then
  8. While dr.Read
  9. If Username2TextBox.Text.Equals(dr("UserName").ToString) Then
  10. Dim dt As DataTable = ds.Tables("Administrator")
  11. dt.Rows(0)("Password") = NewPasswordTextBox.Text
  12. End If
  13. End While
  14. ElseIf OldPassword.Text.Equals("Password") Then
  15. Dim dt As DataTable = ds.Tables("Administrator")
  16. Dim dr = dt.NewRow
  17. Dim bm = Me.BindingContext(dt)
  18. dr.Item("UserName") = Username2TextBox.Text
  19. dr.Item("Password") = NewPasswordTextBox.Text
  20. OleDbDataAdapter1.Fill(ds, "Administrator")
  21. dt = ds.Tables("Administrator")
  22. dt.Rows.Add(dr)
  23. dt.AcceptChanges()
  24. OleDbDataAdapter1.Update(dt)
  25. End If
  26. End If
  27. OleDbConnection1.Close()
  28. End Sub
  29. <vb>
Submitted byrahul111222333 (not verified)on Wed, 02/01/2012 - 23:30

we have an application where i need to run select query for more than 30 to 40 times in different location.the problem which i was facing is for some times i was unable to fetch data from database it was returning null
Submitted bykishan k prajapati (not verified)on Tue, 02/07/2012 - 18:50

cn.Open()
Dim sql As String
sql = "update eform set name = '" & TextBox2.Text & "',address = '" & TextBox3.Text & "',contact = '" & TextBox4.Text & "',dob = '" & TextBox5.Text & "',post = '" & TextBox6.Text & "',depart = '" & ComboBox1.Text & "',head = '" & TextBox7.Text & "',payscale = '" & TextBox8.Text & "',date = '" & TextBox9.Text & "'eid = '" & TextBox1.Text & "'"
Dim cmd As New OleDbCommand(sql, cn)
cmd.ExecuteNonQuery()
MsgBox("Data updated")
cn.Close()
Sir where is the syntax error in this program

Submitted byian ciedric labaro (not verified)on Mon, 02/13/2012 - 20:12

can you help me that program will shows when you add it shows that has already a details
Submitted byThomah2000on Sat, 02/25/2012 - 11:30

Hi, I run the code in vs2010 and am getting an error here "FillListView(lvList, GetData(sSql))" with the exception "System.InvalidCastException was unhandled Message=Unable to cast object of type 'System.Data.OleDb.OleDbException' to type 'System.Data.OleDb.OleDbDataReader'." I don't know what the problem is.
Submitted byKazi (not verified)on Sat, 02/25/2012 - 16:24

HI can help you help mi put all of the info in my listview into database? I already know how to put data at my database using textbox but it will only put one items at a time, so what i did i put all the items in listview but i cant put all items in the listview in my database... do please help me, I'm making a POS, the idea is when the customer buys multiples items, the items i clik in datagrid will be put at my listview but I dont know how to put all the items in my listview into the database.. here's where i dont know what todo Dim ca As New OleDb.OleDbCommandBuilder(dapractice) Dim dsNewRow As DataRow dsNewRow = dspractice.Tables("Practice").NewRow() dsNewRow.Item("Item") = ListView1."I need all of my multiple items in a column to be put in database" dsNewRow.Item("Stock") = ListView1. dspractice.Tables("Practice").Rows.Add(dsNewRow) dapractice.Update(dspractice, "Practice")
Submitted bystapo34on Wed, 03/14/2012 - 23:52

Where can i see the step by step?
Submitted bykaviyarasan (not verified)on Wed, 03/21/2012 - 05:11

i m doing food ordering system and i wan to connect it to ms. access... sumore wen i change food name at the database its nt changing in vb.net... help me... and i aso wan code for update my final result in database back.... tq......

Submitted byAoshi (not verified)on Sat, 03/31/2012 - 14:27

hello,,i have trouble to run my setup/exe in other machine/computer because the database in invalid path,,so my question: how to run my app in other machine without vb or vb.net installed in that machine?? i realy need your help..
Submitted byAoshion Sat, 03/31/2012 - 14:57

hi, i've problem when i running my setup(make with vb6) in other machine without vb6 installed in that machine,because the database path is different, do u have solution for my problem?? thx
Submitted byCMPunkerrron Thu, 05/17/2012 - 21:51

I'm currently developing a sample system wherein the primary key (supposedly id) must be used only once (of course, at it should be)so that there will be no duplicate entries.. I am using vb 2010 and ms access and I'm having problems with the oledbdatareader and the executereader.. I'll just check first your article "Database Programming Made Easy" since MS Access is my database application.. please do comment back if there's any more article I should look for .. thqank you! :)
Submitted bywoolaa (not verified)on Mon, 07/16/2012 - 10:21

Hi..

I have a problem here, it's because i'm using a text box to sent data to data base.. why it's display like this?

INSERT INTO [Inventory_Desktop_Laptop(Manual)][Manual_Host_Name],[Location],[Level_Department],[Type],[Manual_Serial_No],[Manual_Make],[Manual_Model],[Manual_RAM],[HDD],[Owner],[Maint_Expiry],[Received],[Monitor],[Safeboot],[Remark],[Agreement],[Lease_Co],[Lease_From],[Lease_To],[Lease_Period],[Original_Cost],[Status],[Chronology]) VALUES('','','6','6','','','','','','','','','','','','','','','','','','','','')System.Data.SqlClient.SqlException: Incorrect syntax near 'Manual_Host_Name'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at AddManual.Submit1_Click(Object sender, EventArgs e) in C:\Documents and Settings\erizikri.wahab\My Documents\Visual Studio 2008\WebSites\WebSite1\AddManual.aspx.vb:line 71

so, i hope that you can help me by give me some code or what ever.. =D

thx and regard,
woolaa.

Submitted bybernard (not verified)on Thu, 10/25/2012 - 14:09

i need a program in vb.net that will change the value of a field or update a field.
Submitted byAnonymous (not verified)on Wed, 01/16/2013 - 00:04

my project title implementation of mail server using smtp.i have no idea in asp.net with c#.what i do plz help 4 me.
Submitted byAnonymous (not verified)on Thu, 01/17/2013 - 00:40

Am new in .net and programming as well, i would like you help me overcome this challenge. l downloaded your hotel reservation system source code, l have tried to open the "frmAccounts" without success.i did try to edit code by changing reference in WHERE CLAUSE but really l don't even understand the error msg. I quote msg: Run-time error '-2147217365(80040e37)'. The Microsoft Office Access Engine cannot find the input table or query 'Client'. Make sure it exists and that its name is spelled correctly. Please kindly help me out. counting on your usual assistance. thank you.
Submitted byAnonymous (not verified)on Fri, 02/01/2013 - 13:51

Finally I a true sample
Submitted byAnonymous (not verified)on Mon, 04/01/2013 - 00:03

when change text to number in database it produce error! any solution?
Submitted bysmileyon Fri, 04/26/2013 - 17:39

we're having a project system intitled Pupil's information system..we have a problem in query..how can we connect data we entered, example in pupil's information form to Form137??
Submitted byAnonymous (not verified)on Thu, 10/17/2013 - 01:01

i downloaded your code it works for .mdb database can u help me with .accdb database format
Submitted byjmljmson Sun, 12/01/2013 - 21:04

how to save form data in access please step by step simple form like name and address vb.net & access 2007
Submitted byAjosevdaon Wed, 12/18/2013 - 03:48

Hi,can you make this same sistem but with na image too ??
Submitted byAjosevdaon Fri, 02/07/2014 - 15:44

Hi Admin can you make this same Example ,but now with add picture too ??
Submitted bybytehead(clyde) (not verified)on Wed, 02/12/2014 - 16:25

Hi sir, I was studying vb.net for just a couple of weeks, i read some online tutorial on basics of vb.net and tried it and it worked. I also tried to connect database from access to vb and i made it. I also made some buttons to show records in my database like next,previous buttons but i stuck on update,delete, and save button. Until i found this site, i already downloaded your file and studied the codes in there. But my problem is, i dont know the functions of codes in that file, like the syntax "with" "gModule" etc. im working with our thesis "employee management system" our thesis aims to keep the record of the employee's and we also include attendance. In access i have a query that computes the total working hours of employee per day here's the query i use. Number of Hours: DateDiff("n",[Time-in],[Time-out])/60 But i dont know if VB.net have a syntax or code that updates the current time. I hope that you can help me sir, i need to understand every piece of codes in your HowtoAddUpdateDeleteRecord file. thank you
Submitted bybytehead(clyde) (not verified)on Thu, 02/13/2014 - 01:18

In reply to by bytehead(clyde) (not verified)

Hello sir, i tried your codes and i modify it so that i could use it to my project, but when i run my program i got an error says "Failed to connect to Database..System Error Message: Unable to cast object of type 'System.Data.OleDb.OleDbException' to type 'System.Data.OleDb.OleDbDataReader'. I dont know what to do about this error. I hope that you can help me through it sir. thank you.
Submitted byMario Meireles (not verified)on Sat, 03/09/2019 - 22:56

In reply to by bytehead(clyde) (not verified)

Good afternoon I'm having the same problem that you're being so have you solved this problem?
Submitted byhai (not verified)on Sat, 03/01/2014 - 14:14

vb.net add coding in ms access

Add new comment