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
ChumleyYou may want to make sure that an instance of your control was created in th
e code behind. It is usually collapsed at the top of your code behind it sh
ould looks something like
protected withevents sport as system.web.ui.webcontrols.textbox
Todd Meister
"Chumley the Walrus" wrote:

> 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 @.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 (@.sport,@.articleheader)"
> MyCommand.Parameters.Add(New SqlParameter("@.Sport",
> SqlDbType.VarChar, 50))
> MyCommand.Parameters("@.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
> Chumley
>

0 comments:

Post a Comment