Imports System.Data
Imports System.Data.SqlClient
Imports System.Text
Public Class Form1
Dim dr As SqlDataReader
Dim cn As SqlConnection
Dim cm As SqlCommand
Dim sb As New StringBuilder
Dim strSql As String
Dim strCn As String = "Data Source=bkk314;Initial Catalog=DB_For_Webboard;Integrated Security=True"
Dim dtTable As DataTable
Private Sub txtProductID_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtProductID.KeyDown
If e.KeyCode <> Keys.Enter Then
Exit Sub
Else
connection()
sb.Remove(0, sb.Length) '' คำสั่ง Query ข้อมูล
sb.Append("Select productid,productname,price,division,qty,totalprice,datesales From Product")
sb.Append(" where (productid = '" & txtProductID.Text & "')")
strSql = sb.ToString()
com = New SqlCommand()
With com
.CommandType = CommandType.Text
.CommandText = strSql
.Connection = cn
dr = .ExecuteReader()
End With
If dr.HasRows Then
dtTable = New DataTable
dtTable.Load(dr)
txtProductname.Text = dtTable.Rows(0).Item("productname")
txtPrice.Text = dtTable.Rows(0).Item("price")
txtDivision.Text = dtTable.Rows(0).Item("division")
With DataGridView1
.DataSource = dtTable
End With
Else
MsgBox("!!ไม่มีข้อมูล!!", MsgBoxStyle.Critical, "ผลการทำงาน")
End If
End If
End Sub
end class