1

I'm testing databinds in ASP.NET with C# Visual Studio. But I've a irritating problem... To show all products from a database I use a repeater with a datasource query. The query is:

SELECT titel, prijs, Product.artikelnummer, bestandnaam FROM Product INNER JOIN (Foto INNER JOIN Productfoto ON Foto.[foto_id] = Productfoto.[foto_id]) ON Product.[artikelnummer] = Productfoto.[artikelnummer] ORDER BY titel;

Because artikelnummer exist in multiple tables, I must write the table name before it. But when I'll load the data in a repeater, single names work, like:

DataBinder.Eval(Container.DataItem, "bestandnaam")

But when I use the "artikelnummer":

DataBinder.Eval(Container.DataItem, "Product.artikelnummer")

I get a error: DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'Product'.

How could I read the artikelnummer? It is important for me because the product_detailview will load his data from the article number(artikelnummer in dutch)

Anyone??

Jelmer Holtes
  • 73
  • 1
  • 3
  • 7

1 Answers1

2

If you have multiple names that are the same in your SQL output (select portion), use an alias to separate them:

SELECT titel, prijs, Product.artikelnummer as Productartikelnummer, bestandnaam FROM Product INNER JOIN (Foto INNER JOIN Productfoto ON Foto.[foto_id] = Productfoto.[foto_id]) ON Product.[artikelnummer] = Productfoto.[artikelnummer] ORDER BY titel;

However, I only see artikelnummer being returned once so you shouldn't have a problem using it.

DataBinder.Eval(Container.DataItem, "artikelnummer")

The result set will automatically remove the 'Product.' portion for the column name, so you can't perfix your column names with the table name in the binding method.

Chris Gessler
  • 22,727
  • 7
  • 57
  • 83