COPC32: โค้ดตัวอย่างดึงข้อมูลจากMS SQLส่งให้OPC PDF Print E-mail
Written by Administrator   
Thursday, 03 November 2016 14:34

โค้ดตัวอย่างดึงข้อมูลจากMS SQLส่งให้OPCโดยใช้Visual Studio Express (VB)


Imports System.Data.SqlClient
Imports System.Data

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim objConn As New SqlConnection
        Dim objCmd As New SqlCommand
        Dim dtAdapter As SqlDataAdapter
        Dim dt As New DataTable
        Dim strConnString, strSQL As String

        strConnString = "server=(local);uid=usr1;pwd=654321;database=test"
        objConn.ConnectionString = strConnString

        strSQL = "SELECT * FROM t1 WHERE id = " & TextBox1.Text

        dtAdapter = New SqlDataAdapter(strSQL, objConn)

        If dt.Rows.Count > 0 Then
            Me.Label1.Text = dt.Rows(0)("v1")
            'Me.lblName.Text = dt.Rows(0)("Name")
            ' Me.lblEmail.Text = dt.Rows(0)("Email")
            Axcopc1.opcWrt(0, Val(Label1.Text))
        End If

        objConn = Nothing
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        On Error Resume Next

    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
        On Error Resume Next

    End Sub
End Class
Last Updated ( Thursday, 03 November 2016 09:06 )


Wednesday, 18 February 2015 14:02

3000Folderen 110PxThe compact temperature devices of the PR 3000 series provide high accuracy, fast response time AND low temperature drift – without compromise.