System.Data.DataRow error

E

Eugene Anthony

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).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
 
G

Guest

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);
}

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

Hope this helps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top