Private Sub TextBox2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox2.KeyDown
If e.KeyCode = Keys.Enter Then
Dim s As String = ""
s = " select * "
s &= " from [order] [or],order_detail ord,material m,unit un"
s &= " where([or].id_order = ord.id_order)"
s &= " and ord.id_material =m.id_material "
s &= " and ord.id_unit =un.id_unit"
s &= " and [or].id_order = '" & TextBox2.Text & "'"
Dim da As New SqlDataAdapter(s, cn)
Dim ds As New DataSet
da.Fill(ds, "4tb")
If ds.Tables("4tb").Rows.Count = 0 Then
MessageBox.Show("ไม่พบข้อมุลใบสั่งซื้อ")
Exit Sub
End If
Dim n As Integer = 0
n = ds.Tables("4tb").Rows.Count
With ds.Tables("4tb").Rows(0)
id_order.Text = .Item("id_order").ToString
order_date.Text = .Item("dateorder").ToString
ComboBox1.SelectedValue = .Item("id_sup").ToString
txtid.Text = .Item("id_material").ToString
txtname.Text = .Item("name_met").ToString
txtsung.Text = .Item("unitorder").ToString
combobox2.SelectedValue = .Item("uname").ToString
TextBox1.Text = .Item("perunit").ToString
txtprice.Text = .Item("price").ToString
txttotal.Text = .Item("total").ToString
End With
ListView1.Items.Clear()
num = 0
For i As Integer = 0 To n - 1
With ds.Tables("4tb").Rows(i)
Dim lv As New ListViewItem
num += 1
lv.Text = num
lv.SubItems.Add(.Item("id_material").ToString)
lv.SubItems.Add(.Item("name_met").ToString)
lv.SubItems.Add(.Item("price").ToString)
lv.SubItems.Add(.Item("unitorder").ToString)
lv.SubItems.Add(.Item("uname").ToString)
ListView1.Items.Add(lv)
lv = Nothing
End With
Next
End If
End Sub
Tag : .NET, Ms SQL Server 2008, VBScript, Win (Windows App), VS 2008 (.NET 3.x), Windows