Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Frmcustomer_list
Dim conn As New SqlConnection
Private Sub Frmcustomer_list_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strconn As String = ConfigurationManager.ConnetionStrings("plastic_at").connettionstrings
conn = New SqlConnection()
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open()
End With
CusList()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
CusList()
End Sub
Private Sub CusList()
'On Error Resume Next
Dim ds1 As New DataSet
Dim Rs As SqlDataReader
Dim cm As New SqlCommand
Dim SQL As String
Dim i As Integer
SQL = "select * from at_customer order by cs_name"
If Trim(TextBox1.Text) <> "" Then SQL = "select * from at_customer where cs_name like '%" & Trim(TextBox1.Text) & "%' order by cs_name"
cm.Connection = conn
If cm.Connection.State = ConnectionState.Open Then cm.Connection.Close()
cm.Connection.Open()
cm = New SqlCommand(SQL, conn)
Rs = cm.ExecuteReader
If Rs.HasRows = True Then
With DataGridView1
.RowCount = 1
.ColumnCount = 5
.Columns(0).HeaderText = "ID"
.Columns(1).HeaderText = "ที่"
.Columns(2).HeaderText = "ชื่อ - นามสกุล "
.Columns(3).HeaderText = "เบอร์โทรศัพท์"
.Columns(4).HeaderText = "ที่อยู่"
Do While Rs.Read()
i = i + 1
.RowCount = .RowCount + 1
.Item(0, i).Value = Rs("cs_id")
.Item(1, i).Value = i + 1
.Item(2, i).Value = Rs("cs_name")
.Item(3, i).Value = Rs("cs_tel")
.Item(4, i).Value = Rs("cs_address")
If 1 > 50 Then Exit Do
Loop
End With
Rs.Close()
End If
End Sub
Private Sub DataGridView1_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
Dim strconn As String = ConfigurationManager.ConnetionStrings("plastic_at").connettionstrings
'เป็น
Dim strconn As String = ConfigurationManager.ConnetionStrings("plastic_at").ConnectionString