K
Kevin.Li
I am using ASP.NET 2.0.
My DataTable in DataSet are cleared automatically!
The follow is my code:
//--------------- I just keep what core part related to the
problem-----------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
DataTable ds = new DataSet();
string cs = "Data Source=.;Initial Catalog=Northwind;Integrated
Security=True";
protected void Button1_Click(object sender, EventArgs e)
{
string ss = "select
CompanyName,ContactName,ContactTitle,Country,HomePage,Fax,Phone from
Suppliers where "+ selColumn + " = '" + selValue+" ' ";
SqlDataAdapter sda = new SqlDataAdapter(ss,cs);
sda.Fill(ds,"suppliers"); // Everything works well here,
int test = ds.Tables.Count // test will be assigned to
1.
}
protected void btnFirst_Click(object sender, EventArgs e)
{
int test = ds.Tables.Count; // test is 0! Where did my
"suppliers" table gone?
if (ds.Tables["suppliers"].Rows.Count > 0) // Hence, exception:
NullReferenceException.
{
// to do something;
}
}
I still have reference in dataset to the datatable, how can the
datatable be released?
Please help me.. Thanks !
My DataTable in DataSet are cleared automatically!
The follow is my code:
//--------------- I just keep what core part related to the
problem-----------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
public partial class _Default : System.Web.UI.Page
{
DataTable ds = new DataSet();
string cs = "Data Source=.;Initial Catalog=Northwind;Integrated
Security=True";
protected void Button1_Click(object sender, EventArgs e)
{
string ss = "select
CompanyName,ContactName,ContactTitle,Country,HomePage,Fax,Phone from
Suppliers where "+ selColumn + " = '" + selValue+" ' ";
SqlDataAdapter sda = new SqlDataAdapter(ss,cs);
sda.Fill(ds,"suppliers"); // Everything works well here,
int test = ds.Tables.Count // test will be assigned to
1.
}
protected void btnFirst_Click(object sender, EventArgs e)
{
int test = ds.Tables.Count; // test is 0! Where did my
"suppliers" table gone?
if (ds.Tables["suppliers"].Rows.Count > 0) // Hence, exception:
NullReferenceException.
{
// to do something;
}
}
I still have reference in dataset to the datatable, how can the
datatable be released?
Please help me.. Thanks !