Click to See Complete Forum and Search --> : System.Data.DataRow error


solomon_13000
02-07-2007, 02:59 AM
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.ConnectionStrings["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?

RobDavid
02-07-2007, 12:23 PM
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.ConnectionStrings["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?

You have to be careful when databinding to an arraylist or something that isn't a table datasource.

What your Eval("SenderID") is looking for is a column named "SenderID"... That is nowhere in the array definition.

Why don't you just create a datatable and instead of an arraylist? Or better yet...Since you only want 5 rows...Just use "Select Top 5 ...." in your sql statement and just bind the results directly to the rptComments.datasource without any looping?