 |
|
ขอสอบถาม คำสั่ง ค้นหา กรณีที่ค้นหา ชื่อ เเล้ว ไปขึ้นที่ data gridview อีกฟอร์มหนึ่ง อะครับ ไม่ทรับมี ตัวอย่างโค๊ดมั้ยครับ |
|
 |
|
|
 |
 |
|
ขอสอบถาม คำสั่ง ค้นหา กรณีที่ค้นหา ชื่อ เเล้ว ไปขึ้นที่ data gridview อีกฟอร์มหนึ่ง อะครับ ไม่ทรับมี ตัวอย่างโค๊ดมั้ยครับ
เป็นตัวอย่างโค๊ดที่ผมเขียนขึ้นครับ
Code (VB.NET)
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)
|
|
 |
 |
 |
 |
Date :
2011-07-08 23:04:14 |
By :
pisansri |
View :
1139 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก็บค่าดังกล่าวใส่ DataTable แล้วเอาไปใช้กับ DataGridView อีกตัวก็ได้ครับ 
|
 |
 |
 |
 |
Date :
2011-07-10 08:50:39 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีตัวอย่างโค้ด ชักเล็กน้อยมั้ยครับ
|
 |
 |
 |
 |
Date :
2011-07-11 19:42:10 |
By :
pisansri |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็อ้าง
ชื่อform.DataGridView.row.add(ค่าที่1,ค่าที่2,ค่าที่3,ค่าที่4)
ไม่ได้เหรอครับ
|
 |
 |
 |
 |
Date :
2011-07-11 20:37:46 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|