Why my object is null on inserting an HTML input in SQL Database on an ASP.NET website Hosted on ASP.NET web host. My web host is hostbreak.com The code is working fine on localhost using Visual Studios 2019.
Actually I must input this data through HTML input field.
This is the Simple HTML input which is causing NullReferenceException.
My IAUTO.aspx code
<input ID="someid" runat="server" value="somevalue" />
My IAUTO.aspx.cs code
public void Loaddata()
{
SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["someConnectionString"].ConnectionString);
conn.Open();
SqlCommand insertCommand = new SqlCommand("INSERT INTO automobiletable(someid)"
+ "VALUES (@a1)", conn);
insertCommand.Parameters.AddWithValue("@a1", someid.Value.ToString());
I have tried the following method also but getting error In IAUTO.aspx file
<asp:HiddenField ID="someid" runat="server" value="somevalue" />
& In IAUTO.aspx.cs file
//code is same as above
Please help me with this. Maybe my web host offers asp.net only not HTML. I am getting this error
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
ecoio.IAuto.Submit_Click(Object sender, EventArgs e) in J:\EIO\ecoio\ecoio\ecoio\IAuto.aspx.cs:260
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9781022
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1639
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3770.0
Thanks
A Plea: I really need help. I really appreciate stackoverflow.com. They helped me a lot. That's a great service.