insert data into database
hello all,
i have a table "Employee"
Table fields are:-
1) ID int type
2) Date1 date type
3) Reason varchar type
i have made a application in VB, in which this three text field i have taken.
in VB, those fields names are: 1) IDname 2)DateDisplay 3)ReasonDisplay
Now if user enter any data on the form, this should be insert into database.
How to do that using VB?
I have a submit button on the form.
# 1 Re: insert data into database
one way is to use the ADO recordset.
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM <table name>", "<connection string>", adOpenKeyset, adLockOptimistic
rs.AddNew
rs("field1").Value = <value1>
rs("field2").Value = <value2>
rs("fieldN").Value = <valueN>
rs.Update
rs.Close
Set rs = Nothing
if ever the target table has a primary key (won't accept duplicates on field or group of fields) you may just put an error handler.
furthermore, you would create stored procedures for some logics.