Insert,Update,Delete













this is my sample program on how to Insert, Update, and Delete Via your database: the
connection is Done through system DSN, before running this program first create a
simple DSN connection via control panel,if you have no idea on how to create a DSN
Connection just follow this Link How to  create a System DSN of MS Access,follow the
steps that are stated there:in this sample  program will include a simple Error handler,
at a simple calling method


for the INSERT Statement Code this will
look like this:

Conn.Execute "INSERT INTO Names (ID_Num,FName,MName,LName,C_N) " _
& " VALUES ('"& (txtID.Text) & "','"& (txtFN.Text) & "','"& (txtMN.Text) _
& "','"& (txtLN.Text) & "','" & (txtCn.Text) & "')"

'you must state your Database Table Field Name and for the Values is the  control where did 
you store the data to Insert on your Database so for example at the code above is ID_Num is 
my database table field Name and the data that i want to put on its column is the data holds by 
the txtID control or by default is Textbox Control

For the UPDATE Statement:

Conn.Execute "UPDATE Names SET FName='" & (txtFN.Text) & "',MName='" _
& (txtMN.Text) & "',LName='" & (txtLN.Text) & "',C_N='" & (txtCn.Text) & "' 
WHERE ID_Num='" & (txtID.Text) & "'"


'for this Update statement this it is similar on the INSERT statement but on this statement
if State the Database table Name need to follow the corresponding controls where did the
data store,and also,you must Identify the ID-Number for specific data,for you to easily
UPDATE and DELETE a Specific Record on your  DATABASE, like shown above code,
the WHERE CLAUSE which is Responsible on Selecting the specific Data to be Updated:

For the DELETE Statement

Conn.Execute "DELETE * FROM Names WHERE ID_Num='" & (txtID.Text) & "'"

'Delete statement is very simple and easy to do,there is 2 way on how to DELETE data
using this Querry,first is the code shown  above,second will look like this

Conn.Execute "DELETE * FROM Names

'this Delete query will DELETE all the data stored on Names table or on your table,the first 
statement is only DELETE a specific Record where you specified the ID_Num,so making a ID_Num/ID_Number for the Data stored on your Database Table is very important to easily Access,UPDATE,DELETE the Data Selected


The Hardest thing to do is to do nothing ^_^
Happy CODING (^_^)
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • Furl
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati

Leave a comment

Copyright @ Codes-47.Blogspot.Com. Powered by Blogger.