Imports System.Data.SqlClient
Public Class Access_tax
Dim Conn As SqlConnection = New SqlConnection
Dim ds As New DataSet
Dim da As SqlDataAdapter
Private Sub Access_tax_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With cboSearch
.Items.Add("รหัสเจ้าของทรัพย์สิน")
.Items.Add("ชื่อเจ้าของทรัพย์สิน")
.Items.Add("ชื่อเเละสกุลเจ้าของทรัพย์สิน")
.SelectedIndex = 0
End With
With cboSearch_type
.Items.Add("ที่ดิน")
.Items.Add("โรงเรือน")
.Items.Add("ป้าย")
.SelectedIndex = 0
End With
End Sub
Private Sub btnsearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
Dim strConn As String
strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=SSPEGIS;Integrated Security=True"
Conn = New SqlConnection(strConn)
Dim sqlland As String = ""
sqlland = "SELECT * FROM ownerview_1"
If cboSearch.SelectedIndex = 0 Then
sqlland &= " WHERE (PID='" & txtsearch.Text & "')"
ElseIf cboSearch.SelectedIndex = 1 Then
sqlland &= " WHERE (FIRSTNAME LIKE '%" & txtsearch.Text & "%')"
frmowner_list.Show()
End If
sqlland &= " ORDER BY PID"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
da = New SqlDataAdapter(sqlland, Conn)
da.Fill(ds, "ownerview_1")
myGridView.DataSource = ds.Tables("ownerview_1")
txtsearch.Clear()
Dim cs As New DataGridViewCellStyle
cs.Font = New Font("ms sans serif", 10, FontStyle.Regular)
cs.Alignment = DataGridViewContentAlignment.MiddleCenter
cs.ForeColor = Color.Blue
With myGridView
.ColumnHeadersDefaultCellStyle = cs
.Columns(0).HeaderText = "PID"
.Columns(1).HeaderText = "คำนำหน้าชื่อ"
.Columns(2).HeaderText = "ชื่อ"
.Columns(0).Width = 180
.Columns(1).Width = 140
.Columns(2).Width = 100
.Columns(0).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(1).SortMode = DataGridViewColumnSortMode.NotSortable
.Columns(2).SortMode = DataGridViewColumnSortMode.NotSortable
End With
End Sub
End Class
Tag : .NET, Ms SQL Server 2008, VBScript, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)