473,466 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

System.Data.DataRow error

BlogListing.aspx
----------------

<table width="786">
<asp:Repeater ID="rptComments" runat="server">
<ItemTemplate>
<tr>
<td bgcolor="#eaeaea"><%# Eval("SenderID") %></td>
</tr>
<tr>
<td><%# Eval("Description") %></td>
</tr>
<tr>
<td></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
BlogListing.aspx.cs
-------------------

SqlConnection cnn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["myConnection"].Con
nectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "SELECT SenderID, Description FROM Comment WHERE
VideoID=" + Session["videoID"].ToString();
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Comment");

int count;

if (ds.Tables[0].Rows.Count 5)
{
count = 5;
}
else
{
count = ds.Tables[0].Rows.Count;
}

ArrayList pages = new ArrayList();
for (int i = 0; i < count; i++)
{
pages.Add(ds.Tables[0].Rows[i]).ToString();
}

rptComments.DataSource = pages;
rptComments.DataBind();


I am receiving the following error for the code above:
+ $exception {"DataBinding: 'System.Data.DataRow' does not contain a
property with the name 'SenderID'."} System.Exception
{System.Web.HttpException}
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 7 '07 #1
1 2170
Eugene,

You have to import rows like this:

DataTable table = ds.Table[0];
DataTable pages = table.Clone();

int count = Math.Min(5, table.Rows.Count);

for (int i = 0; i < count; i++)
{
pages.ImportRow(table.Rows[i]);
}

rptComments.DataSource = pages;
rptComments.DataBind();

Hope this helps
--
Milosz
"Eugene Anthony" wrote:
BlogListing.aspx
----------------

<table width="786">
<asp:Repeater ID="rptComments" runat="server">
<ItemTemplate>
<tr>
<td bgcolor="#eaeaea"><%# Eval("SenderID") %></td>
</tr>
<tr>
<td><%# Eval("Description") %></td>
</tr>
<tr>
<td></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
BlogListing.aspx.cs
-------------------

SqlConnection cnn = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["myConnection"].Con
nectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = cnn;
myCommand.CommandText = "SELECT SenderID, Description FROM Comment WHERE
VideoID=" + Session["videoID"].ToString();
myCommand.CommandType = CommandType.Text;
SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
myAdapter.Fill(ds, "Comment");

int count;

if (ds.Tables[0].Rows.Count 5)
{
count = 5;
}
else
{
count = ds.Tables[0].Rows.Count;
}

ArrayList pages = new ArrayList();
for (int i = 0; i < count; i++)
{
pages.Add(ds.Tables[0].Rows[i]).ToString();
}

rptComments.DataSource = pages;
rptComments.DataBind();


I am receiving the following error for the code above:
+ $exception {"DataBinding: 'System.Data.DataRow' does not contain a
property with the name 'SenderID'."} System.Exception
{System.Web.HttpException}
How do I solve the problem?

Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Feb 7 '07 #2

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

Similar topics

0
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
0
by: octaviansen | last post by:
Hi, I am experiencing some weird problems with an ASP.NET web application that is making use of System.Data.DataSet and System.Data.DataRow classes. On a machine with single CPU, the...
2
by: Chris Aitchison | last post by:
Hello, I am attempting to have a class that I have written serialize so that it can be both passed as a parameter or return value for a webservice, and also be serialized to disk using the...
1
by: Martin Lindén | last post by:
I got this example written by David J Gottlieb. Which will not compile. I have previously read in the xml doc with myDataSet.ReadXML(Server.MapPath("bills.xml")) Then when i com to this...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
3
by: Floela | last post by:
I keep geting the exception: System.InvalidCastException: Specified cast is not valid. I get this when I try to pass a DataRow into an object method. The line that causes this error is: ...
20
by: djc | last post by:
I get this *intermittently* on a utility I am working on. I don't know whats going on but here are a few points about it: - using VS 2005, running on xp sp2 - program uses multiple threadpool...
1
by: Ryan Liu | last post by:
Hi, When my code run to DataRow.Delete() It throws: System.ArgumentOutOfRangeException: Non-negative number required. Parameter name: length at System.Array.Copy(Array sourceArray, Int32...
4
by: Dariusz Tomon | last post by:
Hello I upgraded my project from Visual Studio 2003 to 2005. The upgrade was performed with no errors but now when I try to build my project (now it's in ..NET 2.0 not .NET 1.1 as was...
2
by: Paulo | last post by:
DataRow dr = (DataRow)ds.Tables.Rows.ItemArray; Error 1 Cannot convert type 'object' to 'System.Data.DataRow' C:\Documents and Settings\Fabio\Meus documentos\Visual Studio...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.