Vx_Chemical
asked on
A field or property with the name 'Id' was not found on the selected data source.
I'm working on a gridview, trying to get it to show the value of a table translated into text from another table, if you get what i mean, but it gives me the above error
A field or property with the name 'Id' was not found on the selected data source.
I cant figure out why it tells me that, table does have a column called Id
Heres the code
<asp:TemplateField HeaderText="Reason For Access">
<ItemTemplate>
<asp:Label ID="locationLabel" runat="server" Text='<%# Reason( (int) Eval("reason_Id") ) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
and the code behind
SqlConnection myConnectionSetting = new SqlConnection(Configuratio nSettings. AppSetting s["Visitor AccessConn ectionStri ng"]);
myConnectionSetting.Open() ;
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM [ReasonForAccess] WHERE (Id = '" + reason_Id + "')", myConnectionSetting);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
location = myReader["Reason"].ToStrin g();
}
The table, contains the columns, Id and Reason
Thanks
A field or property with the name 'Id' was not found on the selected data source.
I cant figure out why it tells me that, table does have a column called Id
Heres the code
<asp:TemplateField HeaderText="Reason For Access">
<ItemTemplate>
<asp:Label ID="locationLabel" runat="server" Text='<%# Reason( (int) Eval("reason_Id") ) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
and the code behind
SqlConnection myConnectionSetting = new SqlConnection(Configuratio
myConnectionSetting.Open()
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("SELECT * FROM [ReasonForAccess] WHERE (Id = '" + reason_Id + "')", myConnectionSetting);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
location = myReader["Reason"].ToStrin
}
The table, contains the columns, Id and Reason
Thanks
Hi,
Try giving the column names in the select list instead of *
Try giving the column names in the select list instead of *
ASKER
hi rajvja, that gives me the same error
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
WHERE (Id = '" + reason_Id + "')"
--from the templatefield, it seems the field may be 'reason_Id', rather than 'Id'. If that is the case, then change the sql statement to :
WHERE (reason_Id = '" + reason_Id + "')"