Last post Jun 27, 2009 06:07 PM by jask2002
Jan 26, 2007 11:46 AM|Mundo|LINK
I know there have been lots of posts on this error, but none of the solutions seem to solve my version of it. I'm trying to fill a GridView with data from an ODBC connection. I don't want to use AutoGenerateColumns, because I want to format the columns using <asp:Boundfield>
tags. If I do this, I get the following error:
A field or property with the name 'StockbookNumber' was not found on the selected data source
I know the field is there and if I set AutoGenerateColumns to 'true', it displays all the columns fine including the
'StockbookNumber' column showing the error. The only column it seems to show without error is the VehicleDescriptio001 column. If I limit the grid to just this column it displays all the rows without error. As soon as I add another column,
it errors immediately after rendering the VehicleDescriptio001 column (correctly) in the first row. It won't work with the StockbookNumber column on its own or any of the other columns for that matter. I'm using the ODBC connector because it's a third party
driver that is my only way of connecting to a bespoke database system. It's also a read-only connection. Any ideas gratefully received before I gnaw my fingers off!
Here's my .aspx code:
<asp:GridView ID="gridVehicles" runat="server" AutoGenerateColumns="False" AllowSorting="False" Font-Size="10pt">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<SelectedRowStyle BackColor="#4A3C8C" ForeColor="#E7E7FF" />
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="VehicleDescriptio001" HeaderText="Description" />
<asp:BoundField DataField="StockbookNumber" HeaderText="Stock Num" />
Here's the .aspx.cs code:
protected void FillVehicleGrid(string dealID, string conString)
// Select statement
string selectSQL = "SELECT VehicleDescriptio001, StockbookNumber ";
selectSQL += "FROM VS_" + dealID + "_UsedVehicleStock ";
selectSQL += "WHERE ACSStatus = 'A' AND deliverydate IS NULL";
// Define ADO.NET objects
OdbcConnection con = new OdbcConnection(conString);
OdbcCommand cmd = new OdbcCommand(selectSQL, con);
// Try to open the database and read the results
reader = cmd.ExecuteReader();
// Bind data to the grid
gridVehicles.DataSource = reader;
catch (Exception err)
lblDealership.Text = "Error getting DMS data. " + err.Message;
ASP.NET 2.0 webform
Feb 05, 2007 05:57 AM|imperialz|LINK
The error u got is most because of .. the field u got from the dataset doesn't match with the field u defined in the Boundcolumn .. But ur code proves that there is no difference btw them .. But my suggesstion is remove the unnecessary blanks in the column
and try this piece of code ..
I'm not sure whether it will help u r not .. but this is just a try ..
datakeyfield="StockbookNumber " .. Include this in the GridView Definition .. I knew this piece of code is only for selecting a particular column in the datagrid .. But it is always better to define that attribute ...
My suggestion is check ur select query ( Column name u get ) and the Column u used to defined in the Gridview ...
Feb 09, 2007 11:35 AM|Mundo|LINK
Jun 27, 2009 06:07 PM|jask2002|LINK
Please have a look at following post. Issue you arw facing is most likely due to Static..
a field or property with the name columnname was not found