Object reference not set to an instance of an object error

  • Thread starter Thread starter Chumley the Walrus
  • Start date Start date
C

Chumley the Walrus

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
 
You may want to make sure that an instance of your control was created in the code behind. It is usually collapsed at the top of your code behind it should looks something like

protected withevents sport as system.web.ui.webcontrols.textbox

Todd Meister
 
Back
Top