Imports System.Data.SqlClient
Public Class Form1
Dim connection As New SqlConnection("Server= local ;Database = test; Integrated Security = true")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TestDataSet.t3' table. You can move, or remove it, as needed.
Me.T3TableAdapter.Fill(Me.TestDataSet.t3)
On Error Resume Next
Axcopc1.cnnec()
'คุณสมบัติ
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'คอลัม
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Name = "Name"
DataGridView1.Columns(1).Name = "Position"
DataGridView1.Columns(2).Name = "Team"
'DataGridView1.Columns(3).Name = "Liter"
End Sub
'เพิ่มข้อมูล ลงดาต้ากิดวิว
Private Sub Populate(name As String, position As String, team As String)
'อเร ข้อมูล
Dim row As String() = New String() {name, position, team}
'เพิ่มลง
'DataGridView1.Rows.Add(row)
End Sub
Private Sub addBtn_Click(sender As Object, e As EventArgs) Handles addBtn.Click
Populate(TextBox1.Text, TextBox2.Text, TextBox3.Text)
'clear textbox
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
[HELP] อยากได้ โค้ด เชื่อม sql กับ vb เพิ่ม ข้อมูลใน from เดียว แล้วอัพเดต ดาต้ากิดวิวตลอดเวลา Code ผมประมาณนี้ครับ
Public Class Form1
Dim connection As New SqlConnection("Server= local ;Database = test; Integrated Security = true")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'TestDataSet.t3' table. You can move, or remove it, as needed.
Me.T3TableAdapter.Fill(Me.TestDataSet.t3)
On Error Resume Next
Axcopc1.cnnec()
'คุณสมบัติ
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
'คอลัม
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Name = "Name"
DataGridView1.Columns(1).Name = "Position"
DataGridView1.Columns(2).Name = "Team"
'DataGridView1.Columns(3).Name = "Liter"
End Sub
'เพิ่มข้อมูล ลงดาต้ากิดวิว
Private Sub Populate(name As String, position As String, team As String)
'อเร ข้อมูล
Dim row As String() = New String() {name, position, team}
'เพิ่มลง
'DataGridView1.Rows.Add(row)
End Sub
Private Sub addBtn_Click(sender As Object, e As EventArgs) Handles addBtn.Click
Populate(TextBox1.Text, TextBox2.Text, TextBox3.Text)
'clear textbox
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