Code ผมเป็นแบบนี้ครับ ถ้าผมต้องการ จะ อับเดต ข้อมูลดาต้ากิดวิล เวลาเราป้อนข้อมูล ผมต้องปรับแจ่งหรือแก้ไขยังไงคับ

กระทู้คำถาม
Imports System.Data.SqlClient

Public Class Form1
    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        On Error Resume Next
        Axcopc1.discnn()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Ds.t3' table. You can move, or remove it, as needed.
        Me.Dt.Fill(Me.Ds.t3)
        On Error Resume Next
        Axcopc1.cnnec()
        Timer1.Enabled = True
        MsgBox("เชื่อมต่อแล้ว")


    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Axcopc1.opcWrt(0, (TextBox1.Text))
        Axcopc1.opcWrt(1, (TextBox2.Text))
        Axcopc1.opcWrt(2, (TextBox3.Text))


        MsgBox("กำลังส่งข้อมูล")


    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Me.TextBox1.Clear()
        Me.TextBox2.Clear()
        Me.TextBox3.Clear()
        Me.TextBox22.Clear()
        Me.TextBox23.Clear()
        Me.TextBox29.Clear()
        Me.TextBox73.Clear()
    End Sub


    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click
        Me.Close()

    End Sub

    Private Sub Timer1_Tick_1(sender As Object, e As EventArgs) Handles Timer1.Tick
        TextBox73.Text = Axcopc1.GetVl(3).ToString
        TextBox22.Text = Axcopc1.GetVl(0).ToString
        TextBox23.Text = Axcopc1.GetVl(1).ToString
        TextBox29.Text = Axcopc1.GetVl(2).ToString

    End Sub

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        Me.T3BindingSource.EndEdit()
        'Me.Dt.Update(Me.Ds.t3)


        Dim sql As String = ” INSERT INTO t3([Time_Date], [Car_no], [Service_no], [Liter]) VALUES (@Time_Date, @val1, @val2, @val3)”

        Dim param(3) As SqlParameter

        param(0) = New SqlParameter(“@Time_Date”, SqlDbType.DateTime)
        param(0).Value = DateTime.Now

        param(1) = New SqlParameter(“@val1”, SqlDbType.NVarChar)
        param(1).Value = Axcopc1.GetVl(0)

        param(2) = New SqlParameter(“@val2”, SqlDbType.Float)
        param(2).Value = Axcopc1.GetVl(1)

        param(3) = New SqlParameter(“@val3”, SqlDbType.Float)
        param(3).Value = Axcopc1.GetVl(2)


        Dim conn As New SqlConnection(“server=(local);uid=testsql;pwd=1234;database=test”)
        conn.Open()


        MsgBox("สำเร็จ")


        Dim command As SqlCommand = conn.CreateCommand()
        command.CommandText = sql
        command.Parameters.AddRange(param)
        Dim nResult As Integer = command.ExecuteScalar()

        conn.Close()
        command.Dispose()
    End Sub

    Private Sub GroupBox3_Enter(sender As Object, e As EventArgs) Handles GroupBox3.Enter

    End Sub
End Class
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่