Saturday 1 October 2016

VB Script for Write into database Table

Write data to MS ACCESS Database

Free code, example code, sample code
Step 1: Open new VB6 project.
Step 2: Select Standard EXE
Step 3:

Step 3: Select the following references

Step 4: Create MS ACCESS Database

Step 5: Add text-box and button

Step 5: Paste this VBScript

Private Sub Command1_Click()
Dim strfile As String
Dim Strcon As String
Dim sqlstr As String
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
strfile = "D:\Database.mdb"
Strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strfile & ";"
Set rs = New ADODB.Recordset
cn.Open Strcon
sqlstr = "SELECT * from Datalog_Table"
rs.Open sqlstr, cn, adOpenDynamic, adLockOptimistic
Text1.Text = rs!DateTime_Column
Text2.Text = rs!Data1_Column
rs.Close
cn.Close
End Sub

Enjoy! Now you can able to write present value and setpoint to database

No comments:

Post a Comment