Question ကို ေဒါင္းလုပ္ လုပ္ပါ။
Download
Question ထဲမွာ Form ကိုမေပးထားပါဘူး။ ကိုယ့္ဘာကို ဖတ္ႀကည့္ျပီး Form design ကိုေဆာက္ရမွာ။
ေအာက္က ပံုအတိုင္းပါပဲ။
ပထမဆံုး SQL Database တစ္ခုေဆာက္ရမယ္။ Database ေဆာက္ပံုေဆာက္နည္းကို အရင္ကေျပာျပီးသားမို ့ ဒီမွာမေျပာေတာ့ဘူး။ Database ေဆာက္ပီးသားလို ့မွတ္ထားလိုက္။ Form ကေနပဲစမယ္။ Display Button ကို ႏွစ္ခ်က္ႏွိပ္လိုက္ရင္ coding ေရးရမယ့္ေနရာ ေရာက္မယ္။
coding ေတြကေတာ့....
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mdept, mname As String
mdept = InputBox("Enter desired Department name: ")
Dim connString As String = ("Data Source=.\sqlexpress; Integrated Security=True; database= staff")
Dim cn As SqlConnection = New SqlConnection(connString)
Dim sql As String = "select * from staff_info;"
Try
Dim ds As New DataSet()
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, cn)
da.Fill(ds)
Dim dv As DataView = New DataView(ds.Tables(0))
dv.RowFilter = "Dept='" & mdept & "'"
dv.Sort = "Salary"
Dim drv As DataRowView
Dim data As String = " "
For Each drv In dv
Dim i As Integer
For i = 0 To dv.Table.Columns.Count - 1
data = data & drv(i) & vbTab
Next
data = data & vbLf
Next
MessageBox.Show(data, "All Staff Info", MessageBoxButtons.OK)
Catch ex As Exception
MessageBox.Show("Error Occured :" & ex.ToString)
Finally
cn.Close()
End Try
End Sub
End Class
အေရးႀကီးတ့ဲ အပိုင္းေလးေတြကို အနီေရာင္နဲ့ျပထားတယ္။ ေမးခြန္းမွာ ပါတဲ့အတိုင္း Filter နဲ့စစ္တာရယ္။ Descending order စီတာရယ္ကို လုပ္ထားတာပါ။ သိပ္ေတာ့အခက္ႀကီး မဟုတ္ပါဘူး။ လက္ေတြ ့လုပ္ႀကည့္ဖို ့ပဲလိုတာပါ။
No comments:
Post a Comment