I am going to past a dataset from First.aspx to Second.aspx.
A whole table will be displayed on First.aspx and partial columns
will be displayed on Second.aspx.
First.aspx view in browser works well if I exclude Second.aspx. But when Second.aspx is included in the project, an error happens.
I can't find what is wrong in my code.
First.aspx.cs
and
Second.aspx.cs
Second.aspx
Any help will be appreciated.
A whole table will be displayed on First.aspx and partial columns
will be displayed on Second.aspx.
First.aspx view in browser works well if I exclude Second.aspx. But when Second.aspx is included in the project, an error happens.
I can't find what is wrong in my code.
Code:
System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object."
Code:
namespace FirstPage
{
public partial class GetStrings : System.Web.UI.Page
{
getStrings g = new getStrings();
protected void Page_Load(object sender, EventArgs e)
{
string strConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(strConnectionString);
DataSet myDataSet = new DataSet();
try
{
myConnection.Open();
// create the data
GenerateDataSet(myDataSet, myConnection);
}
finally
{
myConnection.Close();
// bind each to table to a grid
}
Session["myds"] = myDataSet;
// databind the page
GridView1.DataSource = myDataSet.Tables["Weather"];
GridView1.DataBind();
}
Second.aspx.cs
Code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FirstPage;
public partial class Second : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["myds"];
FillTable(ds);
GridView1.DataSource = ds.Tables["Index"];
GridView1.DataBind();
}
void FillTable(DataSet dset)
{
DataTable indexTable = dset.Tables.Add("Index");
DataColumn indexID =
indexTable.Columns.Add("State", typeof(string));
indexTable.Columns.Add("Division", typeof(string));
indexTable.Columns.Add("MOIST_INDEX", typeof(string));
indexTable.Columns.Add("DROUGHT_INDEX", typeof(string));
}
}
Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Second.aspx.cs" Inherits="Second" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Reference Page="First.aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
Comment