PanoyExpress

Tech. Support And Source Code Provider

Insert,Update,Delete in VB6

this is my sample program on how to Insert,Update, and Delete  data on your

database: the  connection is done through System DSN, before running this

program first create  a simple DSN connection via control panel, in this sample

program will include a simple Error handler, and a simple calling method,and

i use Listview control and command buttons,

Here the Sample Output of this program:

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 followed by the

corresponding controls where  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 query,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

download file

Happy CODING (^_^)

The Hardest Thing to Do is to Do Nothing ^_^

Leave a comment