Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object error

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
OK,

I have a form where the user can add textboxes by clicking a linkbutton, this works perfectly. When I go to insert the text from the textboxes into the database I get a Object reference not set to an instance of an object error (keep in mind that not too long ago it worked perfectly, I took a break and came back and whamo! it dont work anymore).

The sub that enters the text into the database is:
Code:
Dim iCount As Integer
For iCount = 0 To Session("NetTextBoxCount") + 2
   sSQL = "INSERT INTO "
   sSQL &= "dbo.Turbo_Change_Log_Items(change_log_id, change_object, change_object_changes, change_object_type, date_entered)"
   sSQL &= "SELECT "
   sSQL &= " @change_log_id,@change_object,@change_object_changes,1,GETDATE()"
   [b]Dim txt As String = CType(Me.net_xtras.FindControl("object_" & iCount + 2), TextBox).Text[/b]
   Dim txt2 As String = CType(Me.net_xtras.FindControl("changes_" & iCount + 2), TextBox).Text
   Command = New SqlCommand(sSQL, Connection)
   Command.Parameters.AddWithValue("@change_log_id", CType(NewId, Integer))
   Command.Parameters.AddWithValue("@change_object", txt)
   Command.Parameters.AddWithValue("@change_object_changes", txt2)

The error seems to be the bolded line above, but when I click the "Save" button I get the error, yet when I check the database table the data is there. Can someone explain please?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** Do NOT feed Code Gremlins after midnight **
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
is it just icount?

Dim txt As String = CType(Me.net_xtras.FindControl("object_" & iCount), TextBox).Text

-DNG
 
Try debug and check what are you getting at txt.

Sharing the best from my side...

--Prashant--
 
The FindControl method can't find a control with the ID that you've given it. Either the ID is wrong, or the control that you are looking for isn't a child control of whatever "net_xtras" is.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top