Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > เกิด error ฟังก์ชัน Page Unload ค่ะช่วยดูให้หน่อยค่ะ


 

[.NET] เกิด error ฟังก์ชัน Page Unload ค่ะช่วยดูให้หน่อยค่ะ

 
Topic : 052417



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์



Line 35:
Line 36: Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
Line 37: objConn.Close() ผิดตรงนี้ค่ะ
Line 38: objConn = Nothing
Line 39: End Sub

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

นี่เป็นโค้ดค่ะ

Code (VB.NET)
001.Imports System.Data
002.Imports System.Data.OleDb
003. 
004.Partial Class showtypeform
005.    Inherits System.Web.UI.UserControl
006.    Dim objConn As OleDbConnection
007.    Dim objCmd As OleDbCommand
008.    Dim strSQL As String
009.    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
010.        Dim strConnString As String
011.        strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database/mydatabase.mdb") & ";"
012.        objConn = New OleDbConnection(strConnString)
013.        objConn.Open()
014. 
015.        If Not Page.IsPostBack() Then
016.            BindData()
017.        End If
018.    End Sub
019.    Sub BindData()
020.        strSQL = "SELECT * FROM customer"
021. 
022.        Dim dtReader As OleDbDataReader
023.        objCmd = New OleDbCommand(strSQL, objConn)
024.        dtReader = objCmd.ExecuteReader()
025. 
026.        '*** BindData to GridView ***'
027.        myGridView.DataSource = dtReader
028.        myGridView.DataBind()
029. 
030.        dtReader.Close()
031.        dtReader = Nothing
032. 
033.    End Sub
034. 
035.    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
036.        objConn.Close()
037.        objConn = Nothing
038.    End Sub
039. 
040.    Protected Sub myGridView_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs) Handles myGridView.RowCancelingEdit
041.        myGridView.EditIndex = -1
042.        myGridView.ShowFooter = True
043.        BindData()
044.    End Sub
045. 
046.    Protected Sub myGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles myGridView.RowCommand
047.        If e.CommandName = "Add" Then
048.            '*** CustomerID ***'
049.            Dim txtCustomerID As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCustomerID"), TextBox)
050.            '*** Name ***'
051.            Dim txtName As TextBox = CType(myGridView.FooterRow.FindControl("txtAddName"), TextBox)
052.            '*** Email ***'
053.            Dim txtEmail As TextBox = CType(myGridView.FooterRow.FindControl("txtAddEmail"), TextBox)
054.            '*** CountryCode ***'
055.            Dim txtCountryCode As TextBox = CType(myGridView.FooterRow.FindControl("txtAddCountryCode"), TextBox)
056.            '*** Budget ***'
057.            Dim txtBudget As TextBox = CType(myGridView.FooterRow.FindControl("txtAddBudget"), TextBox)
058.            '*** Used ***'
059.            Dim txtUsed As TextBox = CType(myGridView.FooterRow.FindControl("txtAddUsed"), TextBox)
060. 
061.            strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " & _
062.            " VALUES ('" & txtCustomerID.Text & "','" & txtName.Text & "','" & txtEmail.Text & "' " & _
063.            " ,'" & txtCountryCode.Text & "','" & txtBudget.Text & "','" & txtUsed.Text & "') "
064.            objCmd = New OleDbCommand(strSQL, objConn)
065.            objCmd.ExecuteNonQuery()
066. 
067.            BindData()
068.        End If
069.    End Sub
070. 
071. 
072. 
073.    Protected Sub myGridView_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles myGridView.RowDeleting
074.        strSQL = "DELETE FROM customer WHERE CustomerID = '" & myGridView.DataKeys.Item(e.RowIndex).Value & "'"
075.        objCmd = New OleDbCommand(strSQL, objConn)
076.        objCmd.ExecuteNonQuery()
077. 
078.        myGridView.EditIndex = -1
079.        BindData()
080.    End Sub
081. 
082.    Protected Sub myGridView_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs) Handles myGridView.RowEditing
083.        myGridView.EditIndex = e.NewEditIndex
084.        myGridView.ShowFooter = False
085.        BindData()
086.    End Sub
087. 
088. 
089.    Protected Sub myGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs) Handles myGridView.RowUpdating
090.        '*** CustomerID ***'
091.        Dim txtCustomerID As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditCustomerID"), TextBox)
092.        '*** Name ***'
093.        Dim txtName As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditName"), TextBox)
094.        '*** Email ***'
095.        Dim txtEmail As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditEmail"), TextBox)
096.        '*** CountryCode ***'
097.        Dim txtCountryCode As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditCountryCode"), TextBox)
098.        '*** Budget ***'
099.        Dim txtBudget As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditBudget"), TextBox)
100.        '*** Used ***'
101.        Dim txtUsed As TextBox = CType(myGridView.Rows(e.RowIndex).FindControl("txtEditUsed"), TextBox)
102. 
103.        strSQL = "UPDATE customer SET CustomerID = '" & txtCustomerID.Text & "' " & _
104.        " ,Name = '" & txtName.Text & "' " & _
105.        " ,Email = '" & txtEmail.Text & "' " & _
106.        " ,CountryCode = '" & txtCountryCode.Text & "' " & _
107.        " ,Budget = '" & txtBudget.Text & "' " & _
108.        " ,Used = '" & txtUsed.Text & "' " & _
109.        " WHERE CustomerID = '" & myGridView.DataKeys.Item(e.RowIndex).Value & "'"
110.        objCmd = New OleDbCommand(strSQL, objConn)
111.        objCmd.ExecuteNonQuery()
112. 
113.        myGridView.EditIndex = -1
114.        myGridView.ShowFooter = True
115.        BindData()
116.    End Sub
117. 
118. 
119.End Class




Tag : .NET, Ms Access



ประวัติการแก้ไข
2010-11-29 14:42:18
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-11-29 14:41:05 By : csdorm View : 1098 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Connection ยังไม่ได้เปิด หรือมีปัญหาตอนที่เปิด Connection ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-29 15:13:35 By : webmaster
 

 

No. 2



โพสกระทู้ ( 142 )
บทความ ( 0 )



สถานะออฟไลน์


อิอิ ได้แล้วค่ะ ขอบคุณค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-11-29 15:48:04 By : csdorm
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : เกิด error ฟังก์ชัน Page Unload ค่ะช่วยดูให้หน่อยค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่