Am I blind?

Discussion in 'ASP .Net' started by Roy, Feb 3, 2005.

  1. Roy

    Roy Guest

    Sorry for the sea of code. For no apparent reason that I can tell, this
    section of code began producing an "Object reference not set to an
    instance of an object." error. The error occurs on the line I indicate
    below. The code below is nothing in-depth, some variables and a darn
    editable datagrid... I just don't get it.




    FVDConnection = New
    SqlConnection("server=localhost;uid=itv;pwd=;database=test")
    Dim strSQLQuery As String

    'Assign variables to columns
    Dim strBook As String = CType(e.Item.Cells(1).Controls(0),
    TextBox).Text
    Dim strVan As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    Dim strContNum as String = CType(e.Item.Cells(3).Controls(0),
    TextBox).Text
    Dim strVDN as String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
    Dim strPoE as String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
    Dim strShipName as String = CType(e.Item.Cells(6).Controls(0),
    TextBox).Text
    Dim strPod as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
    Dim strCarrier As String = CType(e.Item.Cells(9).Controls(0),
    TextBox).Text
    Dim strPCFN as String = CType(e.Item.Cells(10).Controls(0),
    TextBox).Text
    Dim strTCN as String = CType(e.Item.Cells(11).Controls(0),
    TextBox).Text
    Dim strLastEvent As String = CType(e.Item.Cells(12).Controls(0),
    TextBox).Text
    Dim strLELoc as String = CType(e.Item.Cells(13).Controls(0),
    TextBox).Text
    Dim strLEShipName as String = CType(e.Item.Cells(15).Controls(0),
    TextBox).Text
    Dim strLESCAC as String = CType(e.Item.Cells(16).Controls(0),
    TextBox).Text
    Dim strCCity as String = CType(e.Item.Cells(17).Controls(0),
    TextBox).Text
    Dim strRecon as String = CType(e.Item.Cells(18).Controls(0),
    TextBox).Text


    ********ERROR OCCURS ON FIRST LINE OF THIS strSQLQuery statement***

    strSQLQuery = "UPDATE [firstvd] " & _
    "SET carrier_booking_nr = N'" & Replace(strBook.Trim, "'", "''") & "',
    " & _
    "van_owner = '" & Replace(strVan.Trim, "'", "''") & "', " & _
    "tcon_container_num = N'" & Replace(strContNum.Trim, "'", "''") & "', "
    & _
    "voydoc = '" & Replace(strVDN.Trim, "'", "''") & "', " & _
    "poe = '" & Replace(strPoE.Trim, "'", "''") & "', " & _
    "Ship_Name = '" & Replace(strShipName.Trim, "'", "''") & "', " & _
    "pod = '" & Replace(strPoD.Trim, "'", "''") & "', " & _
    "ocean_carrier_cd = N'" & Replace(strCarrier.Trim, "'", "''") & "', " &
    _
    "PCFN = '" & Replace(strPCFN.Trim, "'", "''") & "', " & _
    "tcn = '" & Replace(strTCN.Trim, "'", "''") & "', " & _
    "lastevent = '" & Replace(strLastEvent.Trim, "'", "''") & "', " & _
    "lasteventloc = '" & Replace(strLELoc.Trim, "'", "''") & "', " & _
    "Lastevent_shipname = N'" & Replace(strLEShipName.Trim, "'", "''") &
    "', " & _
    "lastevent_scac = N'" & Replace(strLEScac.Trim, "'", "''") & "', " & _
    "consigneecity = N'" & Replace(strCCity.Trim, "'", "''") & "', " & _
    "Recon_Status = '" & Replace(strRecon.Trim, "'", "''") & "' " & _
    "WHERE carrier_booking_nr = '"& strPreBook.Trim & "' AND van_owner =
    '"& strPreVan.Trim &"' AND tcon_container_num = '"& strPreCNUM.Trim
    &"'"

    FVDConnection.Open()
    Dim objCommand As SqlCommand = New SqlCommand(strSQLQuery,
    FVDConnection)
    objCommand.ExecuteNonQuery()
    FVDConnection.Close()
     
    Roy, Feb 3, 2005
    #1
    1. Advertising

  2. Roy

    BG Guest

    How about something like this?

    Sub DataGrid1_Update(ByVal sender As Object, ByVal e As
    DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
    Dim strBook As String =
    Convert.ToString(CType(e.Item.FindControl("textBoxName"), TextBox).Text)
    TextBox).Text

    End Sub



    "Roy" <> wrote in message
    news:...
    > Sorry for the sea of code. For no apparent reason that I can tell, this
    > section of code began producing an "Object reference not set to an
    > instance of an object." error. The error occurs on the line I indicate
    > below. The code below is nothing in-depth, some variables and a darn
    > editable datagrid... I just don't get it.
    >
    >
    >
    >
    > FVDConnection = New
    > SqlConnection("server=localhost;uid=itv;pwd=;database=test")
    > Dim strSQLQuery As String
    >
    > 'Assign variables to columns
    > Dim strBook As String = CType(e.Item.Cells(1).Controls(0),
    > TextBox).Text
    > Dim strVan As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    > Dim strContNum as String = CType(e.Item.Cells(3).Controls(0),
    > TextBox).Text
    > Dim strVDN as String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
    > Dim strPoE as String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
    > Dim strShipName as String = CType(e.Item.Cells(6).Controls(0),
    > TextBox).Text
    > Dim strPod as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
    > Dim strCarrier As String = CType(e.Item.Cells(9).Controls(0),
    > TextBox).Text
    > Dim strPCFN as String = CType(e.Item.Cells(10).Controls(0),
    > TextBox).Text
    > Dim strTCN as String = CType(e.Item.Cells(11).Controls(0),
    > TextBox).Text
    > Dim strLastEvent As String = CType(e.Item.Cells(12).Controls(0),
    > TextBox).Text
    > Dim strLELoc as String = CType(e.Item.Cells(13).Controls(0),
    > TextBox).Text
    > Dim strLEShipName as String = CType(e.Item.Cells(15).Controls(0),
    > TextBox).Text
    > Dim strLESCAC as String = CType(e.Item.Cells(16).Controls(0),
    > TextBox).Text
    > Dim strCCity as String = CType(e.Item.Cells(17).Controls(0),
    > TextBox).Text
    > Dim strRecon as String = CType(e.Item.Cells(18).Controls(0),
    > TextBox).Text
    >
    >
    > ********ERROR OCCURS ON FIRST LINE OF THIS strSQLQuery statement***
    >
    > strSQLQuery = "UPDATE [firstvd] " & _
    > "SET carrier_booking_nr = N'" & Replace(strBook.Trim, "'", "''") & "',
    > " & _
    > "van_owner = '" & Replace(strVan.Trim, "'", "''") & "', " & _
    > "tcon_container_num = N'" & Replace(strContNum.Trim, "'", "''") & "', "
    > & _
    > "voydoc = '" & Replace(strVDN.Trim, "'", "''") & "', " & _
    > "poe = '" & Replace(strPoE.Trim, "'", "''") & "', " & _
    > "Ship_Name = '" & Replace(strShipName.Trim, "'", "''") & "', " & _
    > "pod = '" & Replace(strPoD.Trim, "'", "''") & "', " & _
    > "ocean_carrier_cd = N'" & Replace(strCarrier.Trim, "'", "''") & "', " &
    > _
    > "PCFN = '" & Replace(strPCFN.Trim, "'", "''") & "', " & _
    > "tcn = '" & Replace(strTCN.Trim, "'", "''") & "', " & _
    > "lastevent = '" & Replace(strLastEvent.Trim, "'", "''") & "', " & _
    > "lasteventloc = '" & Replace(strLELoc.Trim, "'", "''") & "', " & _
    > "Lastevent_shipname = N'" & Replace(strLEShipName.Trim, "'", "''") &
    > "', " & _
    > "lastevent_scac = N'" & Replace(strLEScac.Trim, "'", "''") & "', " & _
    > "consigneecity = N'" & Replace(strCCity.Trim, "'", "''") & "', " & _
    > "Recon_Status = '" & Replace(strRecon.Trim, "'", "''") & "' " & _
    > "WHERE carrier_booking_nr = '"& strPreBook.Trim & "' AND van_owner =
    > '"& strPreVan.Trim &"' AND tcon_container_num = '"& strPreCNUM.Trim
    > &"'"
    >
    > FVDConnection.Open()
    > Dim objCommand As SqlCommand = New SqlCommand(strSQLQuery,
    > FVDConnection)
    > objCommand.ExecuteNonQuery()
    > FVDConnection.Close()
    >
     
    BG, Feb 3, 2005
    #2
    1. Advertising

  3. On 2 Feb 2005 17:11:24 -0800, Roy <> wrote:

    > Sorry for the sea of code. For no apparent reason that I can tell, this
    > section of code began producing an "Object reference not set to an
    > instance of an object." error. The error occurs on the line I indicate
    > below. The code below is nothing in-depth, some variables and a darn
    > editable datagrid... I just don't get it.
    >
    >
    >
    >
    > FVDConnection = New
    > SqlConnection("server=localhost;uid=itv;pwd=;database=test")
    > Dim strSQLQuery As String
    >
    > 'Assign variables to columns
    > Dim strBook As String = CType(e.Item.Cells(1).Controls(0),
    > TextBox).Text
    > Dim strVan As String = CType(e.Item.Cells(2).Controls(0), TextBox).Text
    > Dim strContNum as String = CType(e.Item.Cells(3).Controls(0),
    > TextBox).Text
    > Dim strVDN as String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
    > Dim strPoE as String = CType(e.Item.Cells(5).Controls(0), TextBox).Text
    > Dim strShipName as String = CType(e.Item.Cells(6).Controls(0),
    > TextBox).Text
    > Dim strPod as String = CType(e.Item.Cells(8).Controls(0), TextBox).Text
    > Dim strCarrier As String = CType(e.Item.Cells(9).Controls(0),
    > TextBox).Text
    > Dim strPCFN as String = CType(e.Item.Cells(10).Controls(0),
    > TextBox).Text
    > Dim strTCN as String = CType(e.Item.Cells(11).Controls(0),
    > TextBox).Text
    > Dim strLastEvent As String = CType(e.Item.Cells(12).Controls(0),
    > TextBox).Text
    > Dim strLELoc as String = CType(e.Item.Cells(13).Controls(0),
    > TextBox).Text
    > Dim strLEShipName as String = CType(e.Item.Cells(15).Controls(0),
    > TextBox).Text
    > Dim strLESCAC as String = CType(e.Item.Cells(16).Controls(0),
    > TextBox).Text
    > Dim strCCity as String = CType(e.Item.Cells(17).Controls(0),
    > TextBox).Text
    > Dim strRecon as String = CType(e.Item.Cells(18).Controls(0),
    > TextBox).Text
    >
    >
    > ********ERROR OCCURS ON FIRST LINE OF THIS strSQLQuery statement***
    >
    > strSQLQuery = "UPDATE [firstvd] " & _
    > "SET carrier_booking_nr = N'" & Replace(strBook.Trim, "'", "''") & "',
    > " & _
    > "van_owner = '" & Replace(strVan.Trim, "'", "''") & "', " & _
    > "tcon_container_num = N'" & Replace(strContNum.Trim, "'", "''") & "', "
    > & _
    > "voydoc = '" & Replace(strVDN.Trim, "'", "''") & "', " & _
    > "poe = '" & Replace(strPoE.Trim, "'", "''") & "', " & _
    > "Ship_Name = '" & Replace(strShipName.Trim, "'", "''") & "', " & _
    > "pod = '" & Replace(strPoD.Trim, "'", "''") & "', " & _
    > "ocean_carrier_cd = N'" & Replace(strCarrier.Trim, "'", "''") & "', " &
    > _
    > "PCFN = '" & Replace(strPCFN.Trim, "'", "''") & "', " & _
    > "tcn = '" & Replace(strTCN.Trim, "'", "''") & "', " & _
    > "lastevent = '" & Replace(strLastEvent.Trim, "'", "''") & "', " & _
    > "lasteventloc = '" & Replace(strLELoc.Trim, "'", "''") & "', " & _
    > "Lastevent_shipname = N'" & Replace(strLEShipName.Trim, "'", "''") &
    > "', " & _
    > "lastevent_scac = N'" & Replace(strLEScac.Trim, "'", "''") & "', " & _
    > "consigneecity = N'" & Replace(strCCity.Trim, "'", "''") & "', " & _
    > "Recon_Status = '" & Replace(strRecon.Trim, "'", "''") & "' " & _
    > "WHERE carrier_booking_nr = '"& strPreBook.Trim & "' AND van_owner =
    > '"& strPreVan.Trim &"' AND tcon_container_num = '"& strPreCNUM.Trim
    > &"'"
    >
    > FVDConnection.Open()
    > Dim objCommand As SqlCommand = New SqlCommand(strSQLQuery,
    > FVDConnection)
    > objCommand.ExecuteNonQuery()
    > FVDConnection.Close()
    >


    well, I don't have time to cross-check them all, but I believe I see 15
    variable declarations, but you have 19 variables concatenated into your
    SQL string...make sure all variables are declared and initialized
    properly, as one of your .Trim statements is failing due to a null
    variable...

    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, Feb 3, 2005
    #3
  4. Roy

    Roy Guest

    Hrmm. As you two correctly guessed (forgot to mention it), the code
    above is within the update command of my datagrid. BG, I'll give it a
    try and get back to ya. Craig, the missing declarations are globals and
    are set = fields in the edit command of my datagrid. I have to pre-set
    them before the user edits the table so the query updates the right
    record. I've done a response write on the globals and they're all
    pulling the right data when the edit button is clicked...

    Here's another tip, btw, the error doesn't kick off until the Update
    button is clicked and the update command is activated. Besides that,
    the page runs fine. Talk about frustrating.
     
    Roy, Feb 3, 2005
    #4
  5. Roy

    Roy Guest

    Interesting...

    I've figured out *how* the error is being caused, I'm just clueless as
    to *why.* You were right about the .Trim statements Craig. Here's the
    scoop:

    The error occurs in the last line of the strSQLQuery: "WHERE
    carrier_booking_nr = '"& strPreBook.Trim & "' AND van­_owner = '"&
    strPreVan.Trim &"' AND tcon_container_num = '"& strPreCN­UM.Trim &"'"

    The system isn't seeing the values of these 3 global variables values.
    I declare and initialize them as demonstrated simplisticly here:

    --Class
    ----Declare Global Var's

    ----Sub edit_command
    -------set GV's = to the correct grid cells

    ----Sub update_command
    -------kick off query which fails to work because it sees the GV's as
    being null

    Now, using a response.write I can tell the GV's are being set within
    the edit_command, by why isn't their value carrying over to the
    update_command? I have enableviewstate = "true," what else can I do
    short of setting them equal to session variables, which I'd rather not
    do...

    Any ideas, theories, etc...?
     
    Roy, Feb 3, 2005
    #5
  6. Roy

    Roy Guest

    Server is a workstation running windows server 2003 which one other
    developer is using as well as his test station. Could he have
    inadvertantly changed a setting in sql server or IIS that generates
    such errors?

    I'm clueless at this point, just grasping at straws...
     
    Roy, Feb 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frogleg

    Free blind browser?

    Frogleg, Sep 2, 2004, in forum: HTML
    Replies:
    52
    Views:
    3,085
    Spartanicus
    Sep 10, 2004
  2. aa
    Replies:
    75
    Views:
    2,282
  3. Hats
    Replies:
    0
    Views:
    528
  4. Dave

    I was blind!

    Dave, Aug 6, 2003, in forum: Python
    Replies:
    0
    Views:
    330
  5. Zachary
    Replies:
    4
    Views:
    355
    John J. Lee
    Jan 11, 2004
Loading...

Share This Page