Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Public Class frm_Planning_Income
Private Sub frm_Planning_Income_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
seclctType()
End Sub
Dim m As String = Date.Now.Month
Dim y As String = Date.Now.Year
Dim inc As String = "01"
Dim numRow As Integer
Dim txt As TextBox
Public Sub seclctType()
Dim myConnection As SqlCeConnection
Dim dt As New DataTable
Dim Adapter As SqlCeDataAdapter
myConnection = New SqlCeConnection("Data Source =" _
+ (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase) + "\AppDatabase.sdf;"))
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = " SELECT Type_ID,Type_Name FROM Account_Category WHERE (Month = '" + m + "' and Year='" + y + "'and Acc_ID='" + inc + "' and Status='1') or (Status='0'and Acc_ID='" + inc + "')"
myCommand.CommandType = CommandType.Text
Adapter = New SqlCeDataAdapter(myCommand)
Adapter.Fill(dt)
numRow = dt.Rows.Count 'ใช้ numRow วนลูปสร้างtextbox
Dim z As Integer = 10
For i = 0 To numRow - 1
'สร้างหน่วยเป็นบาท
Dim lab2 As Label
lab2 = New Windows.Forms.Label
lab2.Name = "lab" & i.ToString
lab2.Location = New System.Drawing.Point(210, 30 + z)
Me.Controls.Add(lab2)
lab2.Text = "บาท"
'สร้างtextbox
txt = New Windows.Forms.TextBox
txt.Name = "textbox" & i.ToString
txt.Location = New System.Drawing.Point(100, 30 + z)
Me.Controls.Add(txt)
'ดึงข้อมูลประเภทมาแสดงใน เลเบิ้ล
Dim lab As Label
lab = New Windows.Forms.Label
lab.Name = "label" & i.ToString
lab.Location = New System.Drawing.Point(15, 30 + z)
Me.Controls.Add(lab)
lab.Text = dt.Rows(i)("Type_Name")
z += 30
Next
btnSave.Location = New System.Drawing.Point(130, 70 + z)
End Sub
End Class