how to return the null or some null table from the method where i return data table in case of some error my code is given below,
public DataTable CostOfKilowat()
{
try
{
DataTable CostDT = new DataTable();
int Dollar = Convert.ToInt32(txtCommission.Text);
CostDT = GetProducts();
DataTable Costtable = GetCostRate(CostDT, Dollar, "DATE,MTU,POWER,COST,VOLTAGE,PERUNITCOST", "DATE", "Group by ");
return Costtable;
}
catch
{
String script = "<script>alert('Enter Valid Cost')</script>";
Page.RegisterStartupScript("script", script);
}
return ;
}
hopes for your suggestions…
From your function definition, I’m assuming you want to return a table so that you can bind that information to a grid or something?
Are you asking how to return an empty grid, or did you really want to know how to return null?
For the empty grid, with all the column names brought back, you would just need to make sure the stored procedure (or whatever server call you make), still
selectsall the fields even when thewhereclause makes it return nothing.Then you have to change your code to always return the table:
If you really want to return null… um..
return null;