Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class ProductAdd
Dim strID As String = ""
Public Property _strID() As String
Get
Return strID
End Get
Set(ByVal value As String)
strID = value
End Set
End Property
Private Sub ProductAdd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim reader As SqlCeDataReader
Dim sql As String
Dim myConnection As SqlCeConnection
myConnection = New SqlCeConnection("Data Source=E:\sasitornpro\sasitornpro\MyDatabase#1.sdf;")
myConnection.Open()
Dim dt As New DataTable
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
sql = "SELECT product_brand FROM product GROUP BY product_brand"
myCommand.CommandText = sql
reader = myCommand.ExecuteReader()
Dim autocomp As AutoCompleteStringCollection = New AutoCompleteStringCollection()
Dim name As String
While (reader.Read())
name = reader("product_brand").ToString()
autocomp.Add(name)
ComboB.Items.Add(name)
reader.Close()
End While
ComboB.AutoCompleteCustomSource = autocomp
End Sub
Private Sub BtSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtSave.Click
If Me.TxtId.Text = "" Then
MessageBox.Show("กรุณาใส่รหัสสินค้า ")
Me.TxtId.Focus()
Exit Sub
End If
If Me.TxtName.Text = "" Then
MessageBox.Show("กรุณาใส่ชื่อสินค้า ")
Me.TxtName.Focus()
Exit Sub
End If
If Me.TxtUnit.Text = "" Then
MessageBox.Show("กรุณาใส่สินค้าในสต็อค")
Me.TxtUnit.Focus()
Exit Sub
End If
If Me.ComboB.Text = "" Then
MessageBox.Show("กรุณาเลือกยี่ห้อสินค้า")
Me.ComboB.Focus()
Exit Sub
End If
Dim myConnection As SqlCeConnection
'myConnection = New SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\Database1.sdf;"))
myConnection = New SqlCeConnection("Data Source=E:\sasitornpro\sasitornpro\MyDatabase#1.sdf;")
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "INSERT INTO [product] ([product_id], [product_name],[unitinstock],[product_brand]) VALUES " & _
" ('" & Me.TxtId.Text & "','" & Me.TxtName.Text & "' ,'" & Me.TxtUnit.Text & "','" & Me.ComboB.Text & "') "
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
MessageBox.Show("อัพเดทข้อมูลสำเร็จ")
Me.Hide()
Dim f As New FormProduct
f.Show()
End Sub
Private Sub BtExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtExit.Click
Me.Hide()
Dim f As New FormProduct
f.Show()
End Sub
End Class