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

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

ชมVDOวิธีการใช้งานที่นี่

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
        objConn.Open()

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

        dtAdapter = New SqlDataAdapter(strSQL, objConn)
        dtAdapter.Fill(dt)

        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.Close()
        objConn = Nothing
    End Sub

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

    End Sub

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

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