Data binding issues

  • Thread starter Thread starter Swagener
  • Start date Start date
S

Swagener

Hi All,

Whatever I have tried - I can't seem to get rid of this error it might
be something simple that I have been over looking please assist

I keep getting this error in explorer

Server Error in '/' Application.
DataBinding: 'System.Data.Common.DbDataRecord' does not contain a
property with the name 'Id'

Web.config file:
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings>
<!-- Windows Authentication-->
<add name="Surveyslol" connectionString="Data Source=.
\SQLSERVER;Initial Catalog=Surveys;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />

</connectionStrings>
<system.web>
<compilation debug="true"/>
<authentication mode="Forms"/>
</system.web>
</configuration>


ASPX Page
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="<%$ ConnectionStrings:Surveyslol %>"
SelectCommand="SELECT DvName, DvcodeNo FROM DivisionName">
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="True"
DataKeyNames="Id"
DataSourceID="SqlDataSource1">
</asp:GridView>
</div>
</form>
</body>
</html>


And If it helps to understand then this is the stack trace
[HttpException (0x80004005): DataBinding:
'System.Data.Common.DbDataRecord' does not contain a property with the
name 'Id'.]
System.Web.UI.DataBinder.GetPropertyValue(Object container, String
propName) +197
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable
dataSource, Boolean dataBinding) +2383

System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable
data) +59
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable
data) +11

System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable
data) +111
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback) +29
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
System.Web.UI.WebControls.GridView.DataBind() +4
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()
+82

System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
+69
System.Web.UI.Control.EnsureChildControls() +87
System.Web.UI.Control.PreRenderRecursiveInternal() +41
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1360
 
Hi swagener,
I keep getting this error in explorer

Server Error in '/' Application.
DataBinding: 'System.Data.Common.DbDataRecord' does not contain a
property with the name 'Id'
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="<%$ ConnectionStrings:Surveyslol %>"
SelectCommand="SELECT DvName, DvcodeNo FROM DivisionName">
</asp:SqlDataSource>
<asp:GridView
ID="GridView1"
runat="server"
AutoGenerateColumns="True"
DataKeyNames="Id"
DataSourceID="SqlDataSource1">

You're saying: Use the data source SqlDataSource1 for the gridview, and
the column "Id" will identify each record. But your select statement
does not include a column named "Id".
Include the column which identifies each record in the SELECT statement,
and use the according column name in the DataKeyNames attribute of the
GridView.

Hope this helps,

Roland
 
Back
Top