transaction problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • denis

    transaction problem

    Hello I'm trying to run this code but i get an error:
    "Object reference not set to an instance of an object. "

    Can somebody help me?
    Thanks


    Try

    '************** *************** *************** *************** *************** *
    ********
    objTransact = objConnection.B eginTransaction ()

    '************** *************** *************** *************** *************** *
    ********

    strSQL = "INSERT INTO Artisti (a_nome) values ('pippo')"

    myDataAdapter = New OleDbDataAdapte r( strSQL, objConnection )
    myDataAdapter.I nsertCommand.Tr ansaction = objTransact
    myDataSet = New DataSet()
    myDataAdapter.F ill( myDataSet, "Artisti")
    myDataTable = myDataSet.Table s("Artisti")

    'Crea u datarow con il record da inserire
    myDataRow = myDataTable.New Row()
    myDataRow("a_no me") = Request.Form("N OME")
    myDataRow("a_co gnome") = Request.Form("C OGNOME")
    myDataRow("a_us r") = Request.Form("U SR")
    myDataRow("a_pw d") = Request.Form("P WD")
    myDataRow("a_az ienda") = Request.Form("A ZIENDA")
    myDataRow("a_in dirizzo") = Request.Form("I NDIRIZZO")
    myDataRow("a_ca p") = Request.Form("C AP")
    myDataTable.Row s.Add(myDataRow )

    DBCommandBuilde r = New OleDbCommandBui lder(myDataAdap ter)
    myDataAdapter.I nsertCommand = DBCommandBuilde r.GetInsertComm and()
    myDataAdapter.U pdate(myDataSet , "Artisti")
    objTransact.Com mit()

    catch ex as exception
    lblStatus.Text += "Error:<br> " & ex.Message
    objTransact.Rol lback()
    Finally
    objConnection.C lose()
    End try


  • Jon Skeet [C# MVP]

    #2
    Re: transaction problem

    denis <dzoddi@mvmnet. com> wrote:[color=blue]
    > Hello I'm trying to run this code but i get an error:
    > "Object reference not set to an instance of an object. "[/color]

    It would help if you could tell us which line the error is occurring
    on...

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • denis

      #3
      Re: transaction problem

      error occures at this line:
      myDataAdapter.I nsertCommand.Tr ansaction = objTransact


      "Jon Skeet [C# MVP]" <skeet@pobox.co m> ha scritto nel messaggio
      news:MPG.1c06bd 1c323b68d398b92 9@msnews.micros oft.com...[color=blue]
      > denis <dzoddi@mvmnet. com> wrote:[color=green]
      > > Hello I'm trying to run this code but i get an error:
      > > "Object reference not set to an instance of an object. "[/color]
      >
      > It would help if you could tell us which line the error is occurring
      > on...
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: transaction problem

        denis <dzoddi@mvmnet. com> wrote:[color=blue]
        > error occures at this line:
        > myDataAdapter.I nsertCommand.Tr ansaction = objTransact[/color]

        Right. That would presumably be because you haven't set up the insert
        command at that point.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • denis

          #5
          Re: transaction problem

          what exactly do I have to do?


          "Jon Skeet [C# MVP]" <skeet@pobox.co m> ha scritto nel messaggio
          news:MPG.1c06c5 87be4b80fa98b92 c@msnews.micros oft.com...[color=blue]
          > denis <dzoddi@mvmnet. com> wrote:[color=green]
          > > error occures at this line:
          > > myDataAdapter.I nsertCommand.Tr ansaction = objTransact[/color]
          >
          > Right. That would presumably be because you haven't set up the insert
          > command at that point.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: transaction problem

            denis <dzoddi@mvmnet. com> wrote:[color=blue]
            > what exactly do I have to do?[/color]

            Exactly what you're doing later - just do it earlier on.

            However, if this kind of problem is troubling you, I seriously suggest
            that you master the basics of .NET before going any further. I find
            it's usually a lot quicker to learn the basics of a platform thoroughly
            before progressing to relatively complicated stuff (like database
            access) than to dive in at the deep end, trying to do everything at
            once.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            • denis

              #7
              Re: transaction problem

              It's hours I'm searching the web for the solution
              I've found other people with the same error but without any response

              I can't understand what you mean (doing later - just do it earlier on)
              Can you correct the error in my code? and give me the right snippet?

              I think this post could be very helpfull for other also

              P.S. I'm not trying to do everything at once, first I've created the script
              for updating a row
              now I'm tryng to add a transaction, then I will go on

              Thanks for your help


              "Jon Skeet [C# MVP]" <skeet@pobox.co m> ha scritto nel messaggio
              news:MPG.1c06d5 4d9790fd1e98b93 1@msnews.micros oft.com...[color=blue]
              > denis <dzoddi@mvmnet. com> wrote:[color=green]
              > > what exactly do I have to do?[/color]
              >
              > Exactly what you're doing later - just do it earlier on.
              >
              > However, if this kind of problem is troubling you, I seriously suggest
              > that you master the basics of .NET before going any further. I find
              > it's usually a lot quicker to learn the basics of a platform thoroughly
              > before progressing to relatively complicated stuff (like database
              > access) than to dive in at the deep end, trying to do everything at
              > once.
              >
              > --
              > Jon Skeet - <skeet@pobox.co m>
              > http://www.pobox.com/~skeet
              > If replying to the group, please do not mail me too[/color]


              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: transaction problem

                denis <dzoddi@mvmnet. com> wrote:[color=blue]
                > It's hours I'm searching the web for the solution
                > I've found other people with the same error but without any response
                >
                > I can't understand what you mean (doing later - just do it earlier on)
                > Can you correct the error in my code? and give me the right snippet?[/color]

                Just move the lines which set up the InsertCommand to before you try to
                *use* the InsertCommand - or vice versa.
                [color=blue]
                > I think this post could be very helpfull for other also
                >
                > P.S. I'm not trying to do everything at once, first I've created the
                > script for updating a row now I'm tryng to add a transaction, then I
                > will go on[/color]

                You're still trying to learn ADO.NET without understanding the basics
                of .NET first though - that's the real problem here.

                --
                Jon Skeet - <skeet@pobox.co m>
                Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

                If replying to the group, please do not mail me too

                Comment

                Working...