|
VB.NET Connect Database กับ VB แบบง่ายๆ |
VB.NET Connect Database กับ VB แบบง่ายๆ Dataset , Connect , isnumeric
form แสดง datagirdview
https://sites.google.com/site/thebunwangs/bug-defect-error/karchidatagridviewnivisualbasic2008
การใช้ Girdview
Imports System.Data
Imports System.Data.SqlClient
Public Class Form3
Dim Conn As New SqlConnection
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Hide()
Form2.Close()
Form4.Close()
DataGridView1.Refresh()
Me.ProductTableAdapter.Fill_product(Me.DataSet1.product)
DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Bisque
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
'TODO: This line of code loads data into the 'DataSet1.product' table. You can move, or remove it, as needed.
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If (DataGridView1.CurrentRow.Cells(0).Selected) Then
Button3.Enabled = True
Button4.Enabled = True
End If
'TextBox1.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Form2.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form4.Show()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If MsgBox("แน่ใจหรือไม่จะลบสินค้านี้ ?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "ยืนยันการออกจากโปรแกรม") = MsgBoxResult.Yes Then
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = "Data Source=Dung-PC\sqlexpress; " & _
"Integrated Security=True; Initial Catalog=test_db; " & _
"Persist Security Info=False"
.Open()
If .State = 1 Then MsgBox("OK")
End With
Dim cmd As New SqlCommand("DELETE from product where product_id=" & DataGridView1.CurrentRow.Cells(0).Value.ToString() & "", Conn)
If cmd.ExecuteNonQuery() Then
MsgBox("Delete Product Success")
Form1.reloadForm3()
End If
End If
End Sub
End Class
connect db และการใช้ cmd
Connect DB
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = "Data Source=name-server\sqlexpress; " & _
"Integrated Security=True; Initial Catalog=test_db; " & _
"Persist Security Info=False"
.Open()
If .State = 1 Then MsgBox("OK")
End With
Dim cmd As New SqlCommand("DELETE from product where product_id=" & DataGridView1.CurrentRow.Cells(0).Value.ToString() & "", Conn)
If cmd.ExecuteNonQuery() Then
MsgBox("Delete Product Success")
Form1.reloadForm3()
End If
|
|
|
|
|
|
|
|
By : |
StePzDJM
|
|
Article : |
บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ |
|
Score Rating : |
|
|
Create Date : |
2012-09-21 |
|
Download : |
No files |
|
Sponsored Links |
|
|
|
|
|
|