Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Am I blind?

Reply
Thread Tools

Am I blind?

 
 
Roy
Guest
Posts: n/a
 
      02-03-2005
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=;datab ase=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(.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(1.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()

 
Reply With Quote
 
 
 
 
BG
Guest
Posts: n/a
 
      02-03-2005
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("textBox Name"), TextBox).Text)
TextBox).Text

End Sub



"Roy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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=;datab ase=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(.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(1.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()
>



 
Reply With Quote
 
 
 
 
Craig Deelsnyder
Guest
Posts: n/a
 
      02-03-2005
On 2 Feb 2005 17:11:24 -0800, Roy <(E-Mail Removed)> 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=;datab ase=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(.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(1.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
 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-03-2005
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.

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-03-2005
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...?

 
Reply With Quote
 
Roy
Guest
Posts: n/a
 
      02-03-2005
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...

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments