473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

DataBinding problems

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(Obj ect
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.T oString());

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

Feb 9 '07 #1
1 3444
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

Feb 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jacek Jurkowski | last post by:
public class Xxx { private string tableName = "" public string TableName { get{return this.tableName;} set { if(value != null)
0
by: Jacek Jurkowski | last post by:
public class Xxx { private string tableName = "" public string TableName { get{return this.tableName;} set { if(value != null)
1
by: | last post by:
Hi, I posted a message a while ago about programatically databinding and got a response that did not make sense to me. Here's a brief description of what I want to do. If I create a regular...
6
by: eye5600 | last post by:
Is there a cure for the problems using databinding with a DateTimePicker? I find that a) sometimes it works, sometimes it doesn't, and b) it fails silently causing all databinding on the DataSet...
3
by: Luis Esteban Valencia | last post by:
Hi, the following code displays a search result in a datagrid and is working without problems. But I think the way I have done is not correct especially databind(). could anyone help me to...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
3
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were...
3
by: Tom McLaughlin | last post by:
I am new to vb.net and I am running into problems understanding DataBinding and its concept. The only examples I find are always talk about Web design, I only want to use this data on my...
5
by: Dennis | last post by:
I am trying to create a form using databinding to a dataset and one of the fields requires the user to select from a list of optons. Any hints on how to do this other than bind the field to a...
7
by: Vlado Jasovic | last post by:
Hello, I'm using typed dataset for databinding to windows controls and I'm having some problems. I'm trying to move all business logic to datatable column_changing events and the problem that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.