Thursday, March 22, 2012

Object reference not set to an instance of an object error

In an asp.net insert data script, I'm getting an Object reference not
set to an instance of an object error on the line that creates the
parameter for @dotnet.itags.org.sport. Not sure why, since I am inserting the field
name correctly in the sql insert statement:

''
Dim InsertCmd As String = "insert into tblArticles
(sport,articleheader) values (@dotnet.itags.org.sport,@dotnet.itags.org.articleheader)"

MyCommand.Parameters.Add(New SqlParameter("@dotnet.itags.org.Sport",
SqlDbType.VarChar, 50))
MyCommand.Parameters("@dotnet.itags.org.Sport").Value =
Server.HtmlEncode(sport.Value)
''''

Here is how I am tagging the input box:

<input type="text" id="sport" value="" runat="server"
??
Thanks in advance
ChumleyDid you declare the control sport ?

The declaration of the control in the aspx should look like:

<asp:TextBox id="sport" runat="server"></asp:TextBox
and in the code behind


protected System.Web.UI.WebControls.TextBox sport;

yeh, i tried declaring the control for the text box and sport, but i got a "value isnt a member of the textbox" error; when i tried using .text with those parameter codings, i got a ".text isnt a member of the parameters" error.

I'm not using code behind (i don't have vs.net) nor c#, so :

protected System.Web.UI.WebControls.TextBox sport;

doesnt make sense
what event takes place when the code is executed.

In the page load add if(!IsPostBack)

maybe that will help
maybe add Name="sport" to your html input textbox and see if that works.

And why aren't you using an <asp:textbox> control?
I don't think value is a valid property... at least for that control... did you try this?

<INPUT id="Text1" type="text" name="Text1" runat="server" value="AA"

0 comments:

Post a Comment