same return types ? DataSet & SqlDataReader

  • Thread starter Thread starter Adie
  • Start date Start date
A

Adie

Hi, is this not possible?

public DataSet getDimensions()
{
}

public SqlDataReader getDimensions()
{
}

I get this error on compile: "Class 'ProductFamily' already defines a
member called 'getDimensions' with the same parameter types"

-- Doesnt seem right to me --
 
Adie said:
Hi, is this not possible?
No.

public DataSet getDimensions()
{
}

public SqlDataReader getDimensions()
{
}

I get this error on compile: "Class 'ProductFamily' already defines a
member called 'getDimensions' with the same parameter types"

-- Doesnt seem right to me --

Why not? Which would you expect to be called in this case:

object o = getDimensions();

or even just

getDimensions();

?
 
Jon said:
Why not? Which would you expect to be called in this case:

object o = getDimensions();

or even just

getDimensions();

I was under the impression that I could overload on return type

DataSet ds = getDimensions()
SqlDataReader dr = getDimensions()
 
Adie said:
I was under the impression that I could overload on return type

DataSet ds = getDimensions()
SqlDataReader dr = getDimensions()

No, you can't.
 
Jon said:
No, you can't.

Heh, yes now I know.

Jon, have you ever seen this error with respect to gatagrid and a dataset?

"Cannot create a child list for field dimensions."

Zero mention on google.
 
Adie said:
Heh, yes now I know.

Jon, have you ever seen this error with respect to gatagrid and a dataset?

"Cannot create a child list for field dimensions."

Zero mention on google.

Ok forget that, I seem to have got it working.
 
Adie said:
Jon, have you ever seen this error with respect to gatagrid and a dataset?

"Cannot create a child list for field dimensions."

Zero mention on google.

Can't say I've ever seen it. What were you trying to do at the time?
 
Jon said:
Can't say I've ever seen it. What were you trying to do at the time?

Ok, this is the error "Cannot create a child list for field [DataSetName]"
which I called "dimensions". I was trying to bind that dataset to the grid,
like this:

DataSet ds = product.getDataSetDimensions();
_DataGrid = new DataGrid();
_Form.Controls.Add(_DataGrid);

// this commented out code works
//// DataTable dt = ds.Tables[0];
//// _DataGrid.DataSource = dt;

// this causes the error
_DataGrid.SetDataBinding(ds,"dimensions");

I think I need to spend more time reading up on the controls and ADO.
 
Adie said:
Ok, this is the error "Cannot create a child list for field [DataSetName]"
which I called "dimensions". I was trying to bind that dataset to the grid,
like this:

DataSet ds = product.getDataSetDimensions();
_DataGrid = new DataGrid();
_Form.Controls.Add(_DataGrid);

// this commented out code works
//// DataTable dt = ds.Tables[0];
//// _DataGrid.DataSource = dt;

// this causes the error
_DataGrid.SetDataBinding(ds,"dimensions");

I think I need to spend more time reading up on the controls and ADO.

Hmm... not sure then, I'm afraid. The table in the dataset is
definitely called dimensions?
 
Jon said:
Adie said:
Ok, this is the error "Cannot create a child list for field [DataSetName]"
which I called "dimensions". I was trying to bind that dataset to the grid,
like this:

DataSet ds = product.getDataSetDimensions();
_DataGrid = new DataGrid();
_Form.Controls.Add(_DataGrid);

// this commented out code works
//// DataTable dt = ds.Tables[0];
//// _DataGrid.DataSource = dt;

// this causes the error
_DataGrid.SetDataBinding(ds,"dimensions");

I think I need to spend more time reading up on the controls and ADO.

Hmm... not sure then, I'm afraid. The table in the dataset is
definitely called dimensions?

Right, well this's where I may be confused. When I created the DataSet I
just called it "dimensions" instead of the actual table name. Maybe this is
why referring to the table via the index works. I thought I could use the
name as a sort of tag or alias being a query can span more than one table.

Here's the jist of what I did:

class GenericData
{
// helper class that allows me to query and add
// any name
public DataSet getDataSetByString(string sql, string dataSetName)
{
SqlConnection mySQLCon = new SqlConnection(@"####");
SqlDataAdapter myAdapter = new SqlDataAdapter();
mySQLCon.Open();
SqlCommand myCommand = new SqlCommand(sql, mySQLCon);
myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand;
DataSet ds = new DataSet(dataSetName); // name the dataset here
myAdapter.Fill(ds);
return ds;
}
}

class ProductFamily
{
public DataSet getDataSetDimensions()
{
GenericData sqlGD = new GenericData();
if (_productType != "")
{
return sqlGD.getDataSetByString(@"SELECT "
+ dimensionArrayToString() + // holds an array of fields for the product
" FROM products WHERE [Product Line] = '"
+ _productType + "' ORDER BY [Product Id];",
"dimensions"); // <-- DataSetName named here on the function call
}
else
{
return sqlGD.returnDataSetNull(); // jiggery pokery, returns a null
// to test against
}
}
}

class DataFormatter
{
public DataFormatter (Form form)
{
_Form = form;
}
public formatProductData(ProductFamily product)
{
DataSet ds = product.getDataSetDimensions();
_DataGrid = new DataGrid();
_Form.Controls.Add(_DataGrid);
DataTable dt = ds.Tables[0];
_DataGrid.DataSource = dt;
}
}

It's basically the fallout from a conversation I had with you a while back
on how to treat products in a database which have a variety of different
attributes, such as width, height, lenght, etc x 100.

I opted for the "wide table" you said you had seperate tables for each
product type/family -- now I spend my time working out how to dynamically
update and display the product data.
 
Adie said:
Right, well this's where I may be confused. When I created the DataSet I
just called it "dimensions" instead of the actual table name.

Hang on a sec - there's a big difference between a DataSet and a
DataTable. A DataSet is a *collection* of tables - and in your binding,
you're saying to find the table called "dimensions" within the DataSet.

Maybe this is
why referring to the table via the index works. I thought I could use the
name as a sort of tag or alias being a query can span more than one table.

Here's the jist of what I did:

class GenericData
{
// helper class that allows me to query and add
// any name
public DataSet getDataSetByString(string sql, string dataSetName)
{
SqlConnection mySQLCon = new SqlConnection(@"####");
SqlDataAdapter myAdapter = new SqlDataAdapter();
mySQLCon.Open();
SqlCommand myCommand = new SqlCommand(sql, mySQLCon);
myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand;
DataSet ds = new DataSet(dataSetName); // name the dataset here
myAdapter.Fill(ds);
return ds;
}
}

Ah - that will have created a table called "Table", I believe.

I personally use data adapters to fill tables, and add those tables to
DataSets separately. So, I'd use:

DataTable table = new DataTable("dimensions");
myAdapter.Fill(table);
ds.Tables.Add(table);

I find this a bit easier to manage.
It's basically the fallout from a conversation I had with you a while back
on how to treat products in a database which have a variety of different
attributes, such as width, height, lenght, etc x 100.

Ah, right. Don't remember that off-hand, I'm afraid, but hopefully the
above will help you.
 
Adie said:
Hi, is this not possible?

public DataSet getDimensions()
{
}

public SqlDataReader getDimensions()
{
}

The compiler is correct. It is not possible. You need to provide
different parameters in order to overload the methods.

-Chris
 
Jon said:
I personally use data adapters to fill tables, and add those tables to
DataSets separately. So, I'd use:

DataTable table = new DataTable("dimensions");
myAdapter.Fill(table);
ds.Tables.Add(table);

I find this a bit easier to manage.

Yeah, I can see that's a little more transparent.
Ah, right. Don't remember that off-hand, I'm afraid, but hopefully the
above will help you.

Well I found another way of tackling the problem, but yes, as *always*,
helpful, thanks.
 
Chris said:
The compiler is correct. It is not possible. You need to provide
different parameters in order to overload the methods.

I don't know why I thought it different than C++, moment of madness I
guess.
 

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

Back
Top