วันพุธที่ 16 มกราคม พ.ศ. 2551
Why JavaScript Topic can't be displayed ?
วันอังคารที่ 15 มกราคม พ.ศ. 2551
Sequence Css Block with A tag
If you place A:hover before A:link or A:visited. The property in A:hover will not be display.
วันอาทิตย์ที่ 13 มกราคม พ.ศ. 2551
BackGround Worker - Progress Bar
Private Sub btnGentoDb_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGentoDb.Click
Me.bgw.RunWorkerAsync(.dgv.Rows.Count - 1) '---- ส่งจำนวนรอบ หรือไม่ส่งก็ว่างไว้
End Sub
Private Sub bgw_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
'เรียก แบบ Function ให้เอา ผลลัพธ์ ใส่ให้ e.result ด้วย
' e.Result = Function(parameter)
'เรียกแบบ Sub
Me.AppendData(e.Argument, worker, e) <<<<<< ไปเรียก Method ที่ทำการประมวลผลเช่นดึงค่ามาจาก Db
End Sub
Private Sub bgw_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles bgw.ProgressChanged
'ทำงานหลัง จากมีการเรียก wk.ReportProgress(Pvalue)
'แสดงผล ความก้าวหน้าการทำงาน
pgb.Value = e.ProgressPercentage
End Sub
Private Sub bgw_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bgw.RunWorkerCompleted
If Not (e.Error Is Nothing) Then
'ทำงานเมื่อเกิด exception ทำให้ การทำงานหยุด
MessageBox.Show(e.Error.Message.ToString, " Error ", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf e.Cancelled Then
' ทำงานหลัง เรียก CancelAsync.
MessageBox.Show(" Cancelled")
Else
'กรณี ปกติ ทำงานเสร็จหมดแล้ว มาจบที่ตรงนี้
'ให้กำหนดว่า(เมื่อทำงานเสร็จแล้วให้ทำอะไร)
' Finally, handle the case where the operation succeeded.
'ก็แค่บอกว่า ทำเสร็จ
Me.btnGentoDb.Enabled = True
End If
End Sub
Special Thanks ..
Gf Board Gf Minilab V.1อืมม ทบทวนความจำเรื่อง Dispose กับ Obj
ถามเรื่องตัวแปรทั่ว ๆ ที่ใช้ใน sub พอใช้เสร็จต้องจัดการอะไรกับตัวแปรนั้นๆ ไหมครับ
ตอบ
การใช้ Using .. End Using
MESSAGE #18854 (อ่าน 158 ครั้ง) Using .... End Using ใช้ยังไงครับ Using .... End Using ใช้ยังไงครับ กับ Try ... Catch ... End Try
ใช้ต่างกันยังไงครับ
ขอขคุณครับ ปอ
-----------------------
Using จะทำการ Dispose ตัวแปร command ให้อัตโนมัติครับ
ส่วน Try .. Catch ใช้ดักเมื่อเกิด throw exception
tony
----------------------
Using sample
Using conn As New SqlConnection(dsn) Using cmd As New SqlCommand("SELECT * FROM Employees", conn) conn.Open() Using rdr As SqlDataReader = cmd.ExecuteReader() While rdr.Read() Console.WriteLine(rdr(0)) End While End Using End Using End Using Nine (นาย) -------------------- ต้วอย่าง แบบไม่ใช้ Using Dim x2 As New Employee("x2") x2.Name = "test"
If (TypeOf x2 Is IDisposable) Then DirectCast(x2, IDisposable).Dispose() End If แบบใช้ Using Using x3 As New Employee("x3") x3.Name = "test" End Using
Iwis -------------------------------
Using cn1 As New SqlConnection(My.Settings.NorthwindConnectionString), _ cmd1 As New SqlCommand(sql1, cn1) cn1.Open() Dim reader As DataReader = cmd1.ExecuteReader() Do While (reader.Read()) Dim sql2 As String sql2 = "...." Using cn2 As New SqlConnection(My.Settings.NorthwindConnectionString), _ cmd2 As New SqlCommand(sql2, cn2) cn2.Open() cmd2.ExecuteNonQuery() End Using Loop reader.Close End Using surrealist ---------------------- Using da As New SqlDataAdapter(sql, cn) Dim cmd As SqlCommand = da.SelectCommand cmd.Parameters.Add("@para1", SqlDbType.XYZ).Value = yourValue ' ---- เมื่อเราสั่ง Fill, DataAdapter จะเอา SelectCommand ของมันไป ExecuteReader ' ---- เพื่อนำข้อมูลที่ได้จาก DataReader มา "Fill" ใส่ DataSet/DataTable ที่เรากำหนด da.Fill(ds, "Table1") End Using ' ... Return(ds)
surrealist
ขอบคุณทุกๆท่านที่มีรายชื่อครับ ที่มา ณ www.greatfriends.biz
