Checking the existance of a dataTable in a dataSet

A

Andy B

Part of my wizard code requires that when each wizardStep is activated, a
check is done to make sure a certain table in a dataset does exist. If it
does exist, bind to it and show the contents in the gridView. If it doesn't
exist, just bind to the gridView and show the emptyDataTemplate. I have this
code so far:

protected void CreateContractWizard_ActiveStepChanged(object sender,
EventArgs e)

{

//Assign the wizard's ActiveStep title to the wizard HeaderText. That way
each wizard step has a visible title

CreateContractWizard.HeaderText = "Create stock contract - " +
CreateContractWizard.ActiveStep.Title;




//Show the Grid for each step when changing between steps.

if(CreateContractWizard.ActiveStepIndex==0) {



//The Header table has data from WizardStep 0. Check to see if the table
exists and either bind to it or show the emptyDataTemplate if it doesn't
exist.

//I get a compiler error: 'Can not apply the ! operator to type DataTable'
in the next line.

if(!((StockContract)Session["StockContract"]).Contract.Tables["Header"]) {

HeaderDisplayGrid.DataBind();

} else {

HeaderDisplayGrid.DataSource =
((StockContract)Session["StockContract"]).Contract.Tables["Header"];

HeaderDisplayGrid.DataBind();

} //End Header table test

} //end ActiveStepIndex = 0 test

}



How do I fix this to make a valid check against the Header table to see if
it exists or not?
 
M

Munna

Part of my wizard code requires that when each wizardStep is activated, a
check is done to make sure a certain table in a dataset does exist. If it
does exist, bind to it and show the contents in the gridView. If it doesn't
exist, just bind to the gridView and show the emptyDataTemplate. I have this
code so far:

protected void CreateContractWizard_ActiveStepChanged(object sender,
EventArgs e)

{

//Assign the wizard's ActiveStep title to the wizard HeaderText. That way
each wizard step has a visible title

CreateContractWizard.HeaderText = "Create stock contract - " +
CreateContractWizard.ActiveStep.Title;

//Show the Grid for each step when changing between steps.

if(CreateContractWizard.ActiveStepIndex==0) {

//The Header table has data from WizardStep 0. Check to see if the table
exists and either bind to it or show the emptyDataTemplate if it doesn't
exist.

//I get a compiler error: 'Can not apply the ! operator to type DataTable'
in the next line.

if(!((StockContract)Session["StockContract"]).Contract.Tables["Header"]) {

HeaderDisplayGrid.DataBind();

} else {

HeaderDisplayGrid.DataSource =
((StockContract)Session["StockContract"]).Contract.Tables["Header"];

HeaderDisplayGrid.DataBind();

} //End Header table test
} //end ActiveStepIndex = 0 test
}

How do I fix this to make a valid check against the Header table to see if
it exists or not?

Hi

try

ds.Tables.Contains("your table name");

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top