// // Object reference not set to an instance of an object - Geeks Portal

Object reference not set to an instance of an object

Last post 07-19-2012 15:01 by subandi08. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-18-2011 8:35

    Object reference not set to an instance of an object

    Dear, all

    Mohon bantuan. saya sedang buat aplikasi. aplikasi ini akan meng-insert record baru jika sebelumnya tidak ada, dan akan mengupdate record jika sebelumnya sudah ada.

    Berikut kodenya :

    Try
                            OleDbConnection1.Open()

                            'set up an SQL select
                            Dim commands As String
                            commands = "SELECT * FROM tblLds WHERE fltno='" & "GA" & fltno & "' AND depsta='" & fromtomatch11.ToString & "' AND arrsta='" & fromtomatch3.ToString.Trim & "' AND datelds='" & depdate2 & "'"
                            OleDbDataAdapter1.SelectCommand.CommandText = commands
                            ' do the select
                            OleDbDataAdapter1.SelectCommand.ExecuteNonQuery()

                            Dim j As Integer = OleDbDataAdapter1.SelectCommand.ExecuteNonQuery
                            If (j = 0) Then
                                'set up an SQL insert
                                Dim commandi As String
                                commandi = "INSERT INTO tblLds VALUES ('" & weightmatch.ToString.Trim & "','" & "GA" & fltno & "','" & ednomatch1.ToString & "','" & bacasign4 & "','" & signmatch5.ToString.Trim & "','" & fromtomatch11.ToString & "','" & fromtomatch3.ToString.Trim & "','" & "PK" & acmatch1.ToString & "','" & vermatch2.ToString & "','" & bacacock & "','" & bacacab1 & "','" & depdate2 & "')"
                                OleDbDataAdapter1.InsertCommand.CommandText = commandi
                                ' do the insert
                                OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()
                           

                                Else


                                'set up an SQL update
                                Dim commandu As String
                                commandu = "UPDATE tblLds SET edno='" & ednomatch1.ToString & "' WHERE fltno='" & "GA" & fltno & "' AND depsta='" & fromtomatch11.ToString & "' AND arrsta='" & fromtomatch3.ToString.Trim & "' AND datelds='" & depdate2 & "'"
                                OleDbDataAdapter1.UpdateCommand.CommandText = commandu
                                ' do the update
                                OleDbDataAdapter1.UpdateCommand.ExecuteNonQuery()
                            End If
                        Catch exceptionObject As Exception
                            MessageBox.Show(exceptionObject.Message)
                        Finally
                        OleDbConnection1.Close()
                    End Try

     

    Untuk proses insert record baru sukses. tapi ketika untuk mengupdate record muncul error "object reference not set to an instance of an object" saat mengeksekusi "OleDbDataAdapter1.UpdateCommand.CommandText = commandu"

    Mohon bantuan. Terimakasih :)

    Ttd,

    Ricoh Sanusi

    • Post Points: 20
  • 07-20-2011 11:38 In reply to

    Re: Object reference not set to an instance of an object

     ok, case closed afteri changed the updating code into :

     

                                'set up an SQL update
                                Dim OleDbUpdateCommand As System.Data.OleDb.OleDbCommand
                                OleDbUpdateCommand = New System.Data.OleDb.OleDbCommand
                                OleDbUpdateCommand.Connection = OleDbConnection1
                                OleDbUpdateCommand.CommandText = "UPDATE tblLds SET edno='" & ednomatch1.ToString & "' WHERE fltno='" & "GA" & fltno & "' AND depsta='" & fromtomatch11.ToString & "' AND arrsta='" & fromtomatch3.ToString.Trim & "' AND datelds='" & depdate2 & "'"
                                OleDbDataAdapter1.UpdateCommand = OleDbUpdateCommand
                                OleDbDataAdapter1.UpdateCommand.ExecuteNonQuery()

     

    Ricoh Sanusi Smile

    • Post Points: 5
  • 07-30-2011 17:35 In reply to

    • isman
    • Top 200 Contributor
    • Joined on 06-07-2011
    • Bogor
    • Posts 21
    • Points 150

    Re: Object reference not set to an instance of an object

    kayaknya OleDbDataAdapter1 harus diinstansiasi lagi setelah mengeksekusi selectcommand
    Filed under:
    • Post Points: 20
  • 07-19-2012 15:01 In reply to

    Re: Object reference not set to an instance of an object

    saya install dotnetnuke 4.5 di windows server 2003 

    saya buat virtual directory untuk dotnetnukenya kemudian execute permission  script only

    tapi setelah saya jalankan errornya sbb: 

     

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       DotNetNuke.HttpModules.UrlRewriteModule.RewriteUrl(HttpApplication app) +318
       DotNetNuke.HttpModules.UrlRewriteModule.OnBeginRequest(Object s, EventArgs e) +506
       System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    

    mungkin ada yang tahu 

    subandi


     

    • Post Points: 5
Page 1 of 1 (4 items)