PC Review


Reply
Thread Tools Rate Thread

DataBinding problems

 
 
Mundo
Guest
Posts: n/a
 
      9th Feb 2007
Hi

I'm pulling my hair out with a problem caused when DataBinding a
DataSet to a web control. I first tried using a GridView but when that
failed, I tried a Repeater. I'm getting the classic
"'System.Data.DataRowView' does not contain a property with the name
X" error message which suggests I'm not putting X in the SELECT
statement. But this is not the case. If I set the GridView to
AutoGenerateColumns="true", it works fine and all the columns in my
SELECT statement appear without problem. But if I try to customise the
columns and use <asp:BoundField/> tags, it all goes pear shaped.
Here's some code:

Data Component:
~~~~~~~~~~~~
private DataSet FillDataSet(string query, string tableName)
{
OdbcConnection con = new OdbcConnection(dmsConString);
OdbcDataAdapter adapter = new OdbcDataAdapter(query, con);

DataSet ds = new DataSet();
try
{
con.Open();
adapter.Fill(ds, tableName);
}
catch (Exception err)
{
//throw err;
}
finally
{
con.Close();
}
return ds;
}

public object GetVehicles(string dealerID)
{
dmsConString = GetDealerConString(dealerID);
string query = "SELECT VehicleDescriptio001,
StockbookNumber, RegistrationNumber ";
query += "FROM VS_" + dealerID + "_UsedVehicleStock ";
query += "WHERE ACSStatus = 'A' AND deliverydate IS NULL";
return FillDataSet(query, "Vehicles");
}


..aspx page:
~~~~~~~~
<asp:GridView ID="gridVehicles" runat="server"
AutoGenerateColumns="False" AllowSorting="False" Font-Size="10pt"
DataKeyField="StockbookNumber" DataKeyNames="StockbookNumber" >
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True"
ForeColor="#F7F7F7" />
<SelectedRowStyle BackColor="#4A3C8C" ForeColor="#E7E7FF" />
<Columns>
<asp:BoundField HeaderText="Description"
DataField="VehicleDescriptio001" />
<asp:BoundField HeaderText="Stock No."
DataField="StockbookNumber" />
<asp:BoundField HeaderText="Reg. No."
DataField="RegistrationNumber" />
</Columns>
</asp:GridView>


..aspx.cs page:
~~~~~~~~~~
protected void lstDealers_SelectedIndexChanged(object sender,
EventArgs e)
{
if (lstDealers.SelectedValue != "")
{
DatabaseComponent.SytnernetDBUtil DB = new
DatabaseComponent.SytnernetDBUtil();

try
{
gridVehicles.DataSource =
DB.GetVehicles(lstDealers.SelectedValue.ToString());
gridVehicles.DataBind();
}
catch (Exception err)
{
lblError.Text = "Exception encountered getting
vehicles: " + err.Message;
}
pnlVehicles.Visible = true;
}
}


Exact error message:
~~~~~~~~~~~~~~~
System.Web.HttpException was unhandled by user code
Message="DataBinding: 'System.Data.DataRowView' does not contain a
property with the name 'StockbookNumber'."
Source="System.Web"
ErrorCode=-2147467259
StackTrace:
at System.Web.UI.DataBinder.GetPropertyValue(Object container,
String propName)
at System.Web.UI.DataBinder.Eval(Object container, String[]
expressionParts)
at System.Web.UI.DataBinder.Eval(Object container, String
expression)
at System.Web.UI.TemplateControl.Eval(String expression)
at ASP.getusedvehicles_aspx.__DataBind__control12(Object
sender, EventArgs e) in c:\Documents and Settings\edmundward\My
Documents\Visual Studio 2005\Projects\VehicleData
\GetUsedVehicles.aspx:line 39
at System.Web.UI.Control.OnDataBinding(EventArgs e)
at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
at System.Web.UI.Control.DataBind()
at System.Web.UI.Control.DataBindChildren()


As you can see I'm definitely SELECTing StockbookNumber in my query,
and the VehicleDescriptio001 field comes back fine, whatever approach
I take. I thought it might be something to do with the ODBC driver I
was using to connect to the remote database, so I tried printing out
the columns in the DataSet to see what they were called from within
there, using the following code in my
lstDealers_SelectedIndexChanged() function:

DataSet ds =
(DataSet)DB.GetVehicles(lstDealers.SelectedValue.ToString());

DataColumnCollection columns =
ds.Tables["Vehicles"].Columns;

foreach (DataColumn column in columns)
{
lblError.Text += column.ColumnName + " : " +
column.DataType + "<br />";
}


This prints out all three column names quite happily as expected. This
suggests to me that the columns are fine in the DataSet, so it can't
be any problem with what the ODBC driver is returning. Am I right in
making this assumption? What else can I try to get to the nitty gritty
of what is going on? Please, please, please somebody out there help if
you can.

Cheers
Mundo

 
Reply With Quote
 
 
 
 
Mundo
Guest
Posts: n/a
 
      12th Feb 2007
Does anybody know how I can view the names of the columns in the
DataSet just before the binding attempt is made? There must be some
properties of some object I can print out. I just can't find the right
one.
Mundo

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with databinding Vanessa Microsoft C# .NET 3 29th May 2008 10:16 AM
Databinding problems with ObjectDataSource Richard Carpenter Microsoft ASP .NET 0 18th Jul 2006 06:09 PM
HELP Databinding Problems with a Dataset Brian Conway Microsoft C# .NET 0 7th Jun 2004 04:18 PM
Problems wit Databinding to a DropDown box Kris Rockwell Microsoft ASP .NET 8 6th Apr 2004 02:14 AM
Databinding Problems Ed Willis Microsoft VB .NET 3 4th Feb 2004 08:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.