Jump to content

Reading, writing and deleting records in access database


Guest onormann

Recommended Posts

Guest onormann

Hia!I'm a total amateur to VBS but need help on a VBS script. This is used in a HMI system from Siemens called WinCC, used for process viewing and control.What I need to is to write to a table in Access, then read these values and then delete records (rows) in Access.By using help functions in WinCC I have this set up:I created an Access database with the WINCC_DATA table and columns (ID,TagValue) with the ID as the Auto Value.Then I can write to Access by the following code:Dim objConnectionDim strConnectionStringDim lngValueDim strSQLDim objCommandstrConnectionString = "Provider=MSDASQL;DSN=SampleDSN;UID=;PWD=;"lngValue = HMIRuntime.Tags("Tag1").ReadstrSQL = "INSERT INTO WINCC_DATA (TagValue) VALUES (" & lngValue & ");"Set objConnection = CreateObject("ADODB.Connection")objConnection.ConnectionString = strConnectionStringobjConnection.OpenSet objCommand = CreateObject("ADODB.Command")With objCommand.ActiveConnection = objConnection.CommandText = strSQLEnd WithobjCommand.ExecuteSet objCommand = NothingobjConnection.CloseSet objConnection = NothingThis actually works fine, pure luck I guess!Can anyone help me with scripts for:1. Reading one record (row) according to a ID number2. Deleting the a record (row) according to a ID numberA complete script would of course be the best thing for a "stupid" amateurlike me! But I would be very thankful for any help!Best regardsonormann

Link to comment
Share on other sites

It just requires sending different SQL statements to the server. Select and delete statements look like this:SELECT * FROM table_name WHERE id=some_valueor:strSQL = "SELECT * FROM WINCC_DATA WHERE id=" & lngValueAnd for delete:DELETE FROM table_name WHERE id=some_valuestrSQL = "DELETE FROM WINCC_DATA WHERE id=" & lngValue

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...