Imports System.Data.SqlClient
Public Class search_land
Dim Conn As SqlConnection = New SqlConnection
Dim ds As New DataSet
Dim da As SqlDataAdapter
Private Sub btnsearch_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsearch.Click
'If MsgBox("คุณต้องการค้นหาข้อมูลใช่หรือไม่ ?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "ค้นหาข้อมูล") = MsgBoxResult.Ok Then
Try
ds.Tables.Clear()
Dim ra As String = ""
If RadioButton1.Checked Then
'Me.Label1.Text = "ตามรหัส"
ra = "LANDID"
End If
If RadioButton2.Checked Then
ra = "PARCEL_CODE"
End If
If TextBox4.Text = "" Then
MsgBox("กรุณากรอกข้อมูลที่ต้องการค้นหา", MsgBoxStyle.Information)
Me.Close()
Else
Dim strConn As String
strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=SSPEGIS;Integrated Security=True"
With Conn
If .State = ConnectionState.Open Then .Close() 'ถ้าเปิดอยู่ให้ปิดการเชื่อมต่อ Connection ก่อน
.ConnectionString = strConn ' กำหนดรูปแบบและฐานข้อมูลสำหรับการติดต่อ
.Open() 'ทำการติดต่อฐานข้อมูล
End With
Dim sql As String = "SELECT * from landView_1 where " & ra & " like '" & TextBox4.Text & "%'"
da = New SqlDataAdapter(sql, Conn)
da.Fill(ds, "landView_1")
myGridView.DataSource = ds.Tables("landView_1")
TextBox4.Clear()
End If
' If dgv1.DataSource = "" Then
'MsgBox("iiii")
' End If
Catch ex As Exception
MessageBox.Show(ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
' End If
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 = "LANDID"
.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
Private Sub dgv_CellMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles myGridView.CellMouseUp
If e.RowIndex = -1 Then Exit Sub
With myGridView
frmland.txtLANDID.Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
frmland.txtPARCEL_CODE.Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
frmland.txtPICTURE_CODE.Text = .Rows.Item(e.RowIndex).Cells(2).Value.ToString()
End With
Me.Close()
End Sub
End Class