 |
|
มีปัญหาเรื่องการ Try...Catch ครับ รบกวนท่านผู้รู้ด้วยครับ |
|
 |
|
|
 |
 |
|
ใช้การ Debug ดูครับ ว่ามันไป Close ตอนไหนครับ
|
 |
 |
 |
 |
Date :
2011-08-05 18:18:35 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแล้วครับ ก็คือ Open ที่แรกก็บรรทัดนั้นแหละครับ ยังไม่ได้ไป open ไหนก่อนเลย ผมลองใส่ Close หลายๆที่ดูแล้ว แต่ก็ไม่ได้อ่ะครับ
|
 |
 |
 |
 |
Date :
2011-08-06 02:21:31 |
By :
PizzaCPE23 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
if (myCon.State == ConnectionState.Open)
{
myCon.Close();
}
myCon.Open();
เวลาจะเปิด Connect ให้เช็คก่อนครับ จะได้ไม่มีปัญหา
|
 |
 |
 |
 |
Date :
2011-08-06 11:04:22 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนที่คุณ Open รอบที่สองบรรทัดที่ 19 คุณยังไม่ได้ปิดเลยนะครับ
คุณ Comment ไว้นี้ครับ ถ้าเอาไปรัน มันก็ไม่ Close ให้สิครับ
|
ประวัติการแก้ไข 2011-08-06 11:31:25
 |
 |
 |
 |
Date :
2011-08-06 11:30:26 |
By :
Marcuz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณ Boat ครับ คือผมลองใส่ไปดูครับเพื่อจะช่วย ได้ทีนี้ใส่ไปมันก็ไม่ได้ช่วยอะไรอ่ะครับ ผมเลยคอมเม้นไว้
คือผมได้ลอง Debug ดูนะครับพบว่า พอโปรแกรมรันมาจนถึง บรรทัดที่ 12 มันก็เด้งไปที่ Catch ex As Exception เลยครับแล้วก็ฟ้อง
ดังที่ได้บอกไว้อะคับ คือมันยังไม่ถึงตรงจะให้ Close อ่ะครับ
|
 |
 |
 |
 |
Date :
2011-08-06 11:50:18 |
By :
PizzaCPE23 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขออนุญาติ โพท Code ใหม่นะครับ
Code (VB.NET)
Protected Sub cmdISave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdISave.Click
If txtInvoiceDate.Text = "" Then
MsgBox("กรุณาใส่วันที่ก่อน", MsgBoxStyle.OkOnly)
Exit Sub
Else
If (txtInvoiceNo.Text = "") Then
' New Invocie
Dim SQL As String
mySqlCon.Open()
SQL = "SELECT Value FROM RunningNumber WHERE Name = 'InvoiceNo'"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
Try
mySqlReader = mySqlCmd.ExecuteReader
While mySqlReader.Read
txtInvoiceNo.Text = "INV" & Format(mySqlReader.Item(0), "000") & "/" & Year(Today)
End While
mySqlReader.Close()
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Try
Dim strInvoiceNo As String
strInvoiceNo = txtInvoiceNo.Text
Dim BCDate As String
BCDate = txtInvoiceDate.Text.Substring(0, txtInvoiceDate.Text.Length - 4) & CStr(CInt(txtInvoiceDate.Text.Substring(txtInvoiceDate.Text.Length - 4)) - 543)
SQL = "INSERT INTO Invoice (InvoiceNo, InvoiceDate, CustomerCode, TotalAmount, VAT, AmountDue) " & _
" VALUES ('" & strInvoiceNo & "',convert(datetime,'" & BCDate & "',103), '" & txtCustomerCode.Text & "' , " & _
" '" & Format(txtTotalAmount.Text, "General Number") & "','" & Format(txtVAT.Text, "General Number") & "','" & Format(txtAmountDue.Text, "General Number") & "')"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
Dim i As Integer
For i = 1 To row_coll.Count
SQL = "INSERT INTO InvoiceLineItem (InvoiceNo, LineItemNo, ProductCode, ProductName, Quantity, UnitPrice, Units, ExtendedPrice) " & _
" VALUES ('" & strInvoiceNo & "','" & i & "'," & _
"'" & row_coll.Item(i).item(2) & "'," & _
"'" & row_coll.Item(i).item(3) & "'," & _
"'" & Format(row_coll.Item(i).item(4), "General Number") & "'," & _
"'" & Format(row_coll.Item(i).item(5), "General Number") & "'," & _
"'" & row_coll.Item(i).item(6) & "'," & _
"'" & Format(row_coll.Item(i).item(7), "General Number") & "')"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
Next
SQL = "UPDATE RunningNumber SET Value = Value + 1 WHERE Name = 'InvoiceNo'"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
UnSetEditMode()
MsgBox("บันทึกเรียบร้อยแล้ว", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox(ex.Message)
End Try
mySqlCon.Close()
Else
Dim SQL As String
mySqlCon.Open()
Try
Dim BCDate As String
BCDate = txtInvoiceDate.Text.Substring(0, txtInvoiceDate.Text.Length - 4) & CStr(CInt(txtInvoiceDate.Text.Substring(txtInvoiceDate.Text.Length - 4)) - 543)
SQL = "UPDATE Invoice SET InvoiceDate = Convert(Datetime,'" & BCDate & "',103) " & _
" ,TotalAmount = '" & Format(txtTotalAmount.Text, "General Number") & "' " & _
" ,CustomerCode = '" & txtCustomerCode.Text & "' " & _
" ,VAT = '" & Format(txtVAT.Text, "General Number") & "' " & _
" ,AmountDue = '" & Format(txtAmountDue.Text, "General Number") & "' " & _
"WHERE InvoiceNo = '" & txtInvoiceNo.Text & "'"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
SQL = "DELETE FROM InvoiceLineItem WHERE InvoiceNo = '" & txtInvoiceNo.Text & "'"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
Dim i As Integer
For i = 1 To row_coll.Count
SQL = "INSERT INTO InvoiceLineItem (InvoiceNo, LineItemNo, ProductCode, ProductName, Quantity, UnitPrice, Units, ExtendedPrice) " & _
" VALUES ('" & txtInvoiceNo.Text & "','" & i & "'," & _
"'" & row_coll.Item(i).item(2) & "'," & _
"'" & row_coll.Item(i).item(3) & "'," & _
"'" & Format(row_coll.Item(i).item(4), "General Number") & "'," & _
"'" & Format(row_coll.Item(i).item(5), "General Number") & "'," & _
"'" & row_coll.Item(i).item(6) & "'," & _
"'" & Format(row_coll.Item(i).item(7), "General Number") & "')"
mySqlCmd = New SqlCommand(SQL, mySqlCon)
mySqlCmd.ExecuteNonQuery()
Next
UnSetEditMode()
MsgBox("บันทึกเรียบร้อยแล้ว", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox(ex.Message)
End Try
mySqlCon.Close()
End If
End If
End Sub
|
 |
 |
 |
 |
Date :
2011-08-06 11:51:46 |
By :
PizzaCPE23 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณทุกท่านมากนะครับที่มาช่วยเหลือผม
ผมได้ทำทุกวิธีทางแล้ว DeskCheck ก็แล้วสุดท้าย
โค้ดผมไม่ได้ผิดอะไรเลยครับ ถูกหมดทุกบรรทัดตั้งแต่แรกแล้ว
ที่ผมทำคือ ลบ textbox ที่ชื่อ txtInvoiceNo ออกแล้วสร้าง textbox ใหม่ใช้ชื่อเดิมแล้วลองรัน
ปรากฏว่าผ่านครับ งงไปเลยทีเดียวว่า ก็ไม่เข้าใจว่าทำไมทำแบบนี้แล้วถึงผ่าน ฮ่าๆๆๆๆ งงเหมือนกัน
ยังไงก็ขอบคุณทุกท่านมากๆครับ
|
 |
 |
 |
 |
Date :
2011-08-07 13:01:56 |
By :
PizzaCPE23 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกี่ยวกันไหม๊ครับ
|
 |
 |
 |
 |
Date :
2011-08-08 06:40:06 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|