R
Roy
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()
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()