Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

The field (caption_id) is in the query but I get the following error!!!
The field's name is correctly written in query.

DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'caption_id'.

VB
  Dim dat2 As SqlClient.SqlDataReader
       Dim com_str As String
com_str = "Select TOP (5) id, caption, SUBSTRING(context, 1, 140) AS context, photo, date_submit, caption_id, date_day, date_month, date_year, date_minute, date_hour FROM news;"
       Dim com1 As New SqlClient.SqlCommand(com_str, connection.sql_connect)
       dat2 = com1.ExecuteReader
       DataList2.DataSource = dat2
       DataList2.DataBind()
        dat2.Close()


ASP.NET
<asp:DataList ID="DataList2" runat="server" Height="53px" Width="523px">
<ItemTemplate>
 <table border="0" style="width: 99%; height: 147px">

<tr>

<td align="right">
<a style="text-decoration: none;" href='news-detail.aspx?news_id=<%#DataBinder.Eval(Container.DataItem, "id")%>&caption_id=<%#DataBinder.Eval(Container.DataItem, "caption_id")%>'><img style="border:0" src="images/continue.jpg" /> 
</a>
</td>
</tr>


<tr>
<td align="right" height="143" rowspan="3" style="width: 162px">
<img Height="140" Width="158" src='news-images/<%# DataBinder.Eval(Container.DataItem,"photo") %>' /></td>
<td valign="top" align="right" height="26" style="font-family: Tahoma; font-size: 9pt; color: #000000; font-weight: bold"><%#DataBinder.Eval(Container.DataItem, "caption")%></td>
</tr>
<tr>
<td valign="top" align="justify" dir="rtl" height="92" style="font-family: Tahoma; font-size: 10pt; color: #000000"><%#DataBinder.Eval(Container.DataItem, "context")%><a dir="rtl">....</a></td>
</tr>


</table>

</ItemTemplate> 

</asp:DataList>
Posted
Updated 2-Jun-12 11:34am
v3

1 solution

The answer is in the error message:

"DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'caption_id'."

It's pretty explicit: "news" does not contain a column called "caption_id"
 
Share this answer
 
Comments
taha bahraminezhad Jooneghani 3-Jun-12 3:29am    
and he said He has this column in database!
this is the reason of his confusion!
OriginalGriff 3-Jun-12 3:38am    
Then he needs to check he is looking at the right table: the error is pretty explicit...
moodyCoder 5-Jun-12 2:27am    
What an expert programmer's eye you have OriginalGriff...

You are definitely correct!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900