gridviewからSQLサーバーデータベースにデータを挿入/更新しているときに、 「オブジェクト参照がオブジェクトのインスタンスに設定されていません」というエラーが発生します。誰でも助けてください。
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();
}
}
エラーメッセージは次のとおりです。
オブジェクト参照がオブジェクト インスタンスに設定されていません。
説明:現在のWebリクエストの実行中に未処理の例外が発生しました。エラーとエラーがコードのどこで発生したかについての詳細は、スタックトレースを確認してください。
例外の詳細:System.NullReferenceException:オブジェクト参照がオブジェクトのインスタンスに設定されていません。
ソースエラー:
107行目:txtNewContact =(TextBox)GridAllStore.FooterRow.FindControl( "txtNewContact");
108行目:txtNewAddress =(TextBox)GridAllStore.FooterRow.FindControl( "txtNewAddress");
109行目:tastore.Insert(txtNewName.Text、txtNewContact.Text、txtNewAddress.Text);
110行目:FillGrid();
111行目:}ソースファイル:C:\ Users \ DELL \ Documents \ Visual Studio 2010 \ Projects \ WebApplication1 \ WebApplication1 \ AdminPanel.aspx.cs行:109