Using 'New' for 'Object reference not set to an instance of an object' error doesn't work...

Hi,

I'm trying to build a sql insert statement by reading through each textbox the footer of a DataGrid control. Here's my datagrid code:

                
0 capella07 4/30/2007 2:40:45 PM

Well, the thing I see is that you are trying to dynamically create a textbox with an ID that already exists.

If you can't access the textbox without the Dim .. as TextBox (have you tried?) then maybe just use a WithEvent to expose the textbox.

The reason for the "squiqly", I would imagine is that you are duplicating IDs... 


Andrew S. Erwin
Software Developer
ReflectSystems, Inc.

0 cyberwin 4/30/2007 2:50:31 PM

Hey, cyberwin. Thanks for replying.

I see what you're saying about "creating a textbox with an ID that already exists". No, I hadn't tried to access it without the Dim until you mentioned it. I tried working with that, but couldn't figure out exactly how to do it (you're talking with a real VB.NET noob here!). I'd appreciate it if you could "point me in the right direction" as far as doing that.

Thanks,

Capella07


"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0 capella07 4/30/2007 3:03:39 PM

By the way, here's what I tried:

                
0 capella07 4/30/2007 3:06:08 PM

When accessing the textbox, you should have direct control. Meaning, you don't need to use FindControl.

If you want to see the value of the textbox (what is in the textbox) just user

Dim x as String = txtDefaultPayRate.Text

If you cannot access it, you can place a protected withevent in your code behind and use the find control to expose it...

Andrew S. Erwin
Software Developer
ReflectSystems, Inc.

0 cyberwin 4/30/2007 3:17:24 PM

Ah, that's the deal, there. The textboxes are in a datagrid, so I do need to use FindControl (at least as I understand this, I need to).

So, according to what you said in your last post, I'd need to us a "protected withevent". How do I do that and have it work with the Sub I've got (below) that handles the Insert command?

                
0 capella07 4/30/2007 3:28:01 PM

Well, first, try accessing the textbox directly.

A WithEvent should be placed inside your class, but outside of any sub or function...

An example would be...Imports System.Data.SqlClient

Imports System 

Partial Class documents
    Inherits System.Web.UI.Page

    Protected WithEvents (whatever the name of the textbox is) As TextBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
...

 

But I am pretty sure if you try to access the textbox directly it will work... 


Andrew S. Erwin
Software Developer
ReflectSystems, Inc.

0 cyberwin 4/30/2007 3:35:33 PM

Thanks, cyberwin

I'll work with that for a while and see what I can do.

Wish me luck!


"f u cn rd ths, u cn gt a gd jb n cmptr prgmmng." - Anon
0 capella07 4/30/2007 3:55:55 PM

dgSqlConn = New SqlConnection("DATACONNECTIONINFORMATION")

Should be DIM dgSqlConn as New SqlConnection(...)


Andrew S. Erwin
Software Developer
ReflectSystems, Inc.

0 cyberwin 5/24/2007 6:31:58 PM
Reply:

Thread closed