I am getting "Object reference not set to an instance of an object" error while inserting/updating data into a sql server database from gridview . Anybody please help .
protected void GridAllStore_RowCommand(object sender, GridViewCommandEventArgs e)
{
storelocatorDataSetTableAdapters.storedbTableAdapter tastoreInsert = new storelocatorDataSetTableAdapters.storedbTableAdapter();
if (e.CommandName.Equals("Insert"))
{
TextBox txtNewName = new TextBox();
TextBox txtNewContact = new TextBox();
TextBox txtNewAddress = new TextBox();
txtNewName = (TextBox)GridAllStore.FooterRow.FindControl("txtNewName");
txtNewContact = (TextBox)GridAllStore.FooterRow.FindControl("txtNewContact");
txtNewAddress = (TextBox)GridAllStore.FooterRow.FindControl("txtNewAddress");
tastore.Insert(txtNewName.Text, txtNewContact.Text, txtNewAddress.Text);
FillGrid();
}
}
Here is the error message:
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:
Line 107: txtNewContact = (TextBox)GridAllStore.FooterRow.FindControl("txtNewContact");
Line 108: txtNewAddress = (TextBox)GridAllStore.FooterRow.FindControl("txtNewAddress");
Line 109: tastore.Insert(txtNewName.Text, txtNewContact.Text, txtNewAddress.Text);
Line 110: FillGrid();
Line 111: }Source File: C:\Users\DELL\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\AdminPanel.aspx.cs Line: 109