Private Sub search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles search.Click
If txtFind.Text = "" Then
MessageBox.Show("ท่านยังไม่ระบุข้อมูลที่ต้องการค้นหา!!!", "คำเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtFind.Focus()
Exit Sub
End If
Try
Dim strsql As String = ("SELECT * FROM ram where ram_brand like '%" & txtFind.Text & "%' ")
With sqlConn
If .State = ConnectionState.Open Then .Close()
.Open()
End With
With sqlDA
.SelectCommand = New SqlCommand(strsql, sqlConn)
dsShow.Clear()
.Fill(dsShow, "ram")
End With
If dsShow.Tables("ram").Rows.Count > 0 Then
With dgshow
.DataSource = dsShow.Tables("ram")
dgshow.Columns(0).HeaderText = "รหัส"
dgshow.Columns(1).HeaderText = "ยี่ห้อ"
dgshow.Columns(2).HeaderText = "ประเภท"
dgshow.Columns(3).HeaderText = "ขนาด"
dgshow.Columns(4).HeaderText = "บัส"
dgshow.Columns(5).HeaderText = "ราคา"
dgshow.Columns(6).HeaderText = "ประกัน"
dgshow.Columns(0).Width = 60
dgshow.Columns(1).Width = 100
dgshow.Columns(2).Width = 80
dgshow.Columns(3).Width = 80
dgshow.Columns(4).Width = 80
dgshow.Columns(5).Width = 70
dgshow.Columns(6).Width = 70
dgshow.Show()
.ReadOnly = True
.AllowUserToAddRows = False
End With
Else
MessageBox.Show("ไม่พบข้อมูลที่ค้นหา")
txtFind.Focus()
txtFind.Text = ""
End If
Catch ex As Exception
MessageBox.Show("เกิดข้อผิดพลาดเนื่องจาก" & ex.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
txtFind.Text = ""
sqlConn.Close()
End Try
End Sub
ขอบคุณคับ
Tag : .NET, Ms SQL Server 2008, Crystal Report, VS 2010 (.NET 4.x), Windows
Dim dtGV As New DataTable()
dtGV.Columns.Add("C1", GetType(String))
dtGV.Columns.Add("C2", GetType(String))
dtGV.Columns.Add("C3", GetType(String))
dtGV.Columns.Add("C4", GetType(String))
dtGV.Columns.Add("C5", GetType(String))
dtGV.Rows.Add(New Object() {})
dtGV.Rows.Add(New Object() {})
dtGV.Rows.Add(New Object() {})
dtGV.Rows.Add(New Object() {})
Me.dgvLayout.RowTemplate.MinimumHeight = 30
Me.dgvLayout.AutoGenerateColumns = False
Me.dgvLayout.ColumnHeadersHeight = 30
For i As Integer = 0 To 23
Me.dgvLayout.Columns.Add(New DataGridViewTextBoxColumn() With {.Name = i + 1, .Width = 30})
Me.dgvLayout.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.dgvEditMsg.Columns.Add(New DataGridViewTextBoxColumn() With {.Name = i + 1, .Width = 90})
Me.dgvEditMsg.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Me.dgvEditMsg.Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
Next
For Each dr As DataRow In dtGV.Rows
Me.dgvLayout.Rows.Add(dr.ItemArray)
Next