Can't find a property name

  • Thread starter Thread starter King Coffee
  • Start date Start date
K

King Coffee

Hi,

Your help is greatly appreciated. The following code snippet displays the
Object Data OK... but if I try to update the edited fields SeqNum or Title I
get the following error message:

Could not find a property named 'SeqNum' on the type specified by the
DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'.

How do I define the Binding objects property names ??


<asp:GridView ID="GridView1" Runat="server" DataSourceID="ObjectDataSource1"
AutoGenerateColumns="False" Width="100%" DataKeyNames="PicID" />
<Columns>
<asp:templatefield HeaderText="Sequence" ItemStyle-Width="50px" >
<itemtemplate>
<%#Eval("SeqNum")%>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtSeq" runat="server"
Text='<%#Bind("SeqNum")%>' />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtSeq"
Text="require" />
</edititemtemplate>
<itemstyle verticalalign="middle" width="50px" />
</asp:templatefield>
<asp:templatefield HeaderText="Title">
<itemtemplate>
<%#Eval("Title")%>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtTitle" runat="server"
Text='<%#Bind("Title")%>' Width="300px" />
</edititemtemplate>
<itemstyle verticalalign="middle" width="50%" />
</asp:templatefield>
</Columns>



<asp:ObjectDataSource ID="ObjectDataSource1"
TypeName="BOL.Pics"
DataObjectTypeName="BOL.Pics"
SelectMethod="GetPics"
UpdateMethod="Update"
DeleteMethod="Delete"
Runat="server" >
<UpdateParameters>
<asp:Parameter Name="PicID", Type="Int32" />
<asp:Parameter Name="SeqNum", Type="Int32" />
<asp:Parameter Name="Title" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="PicID", Type="Int32" />
<asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
Name="AptId" />
</DeleteParameters>
<SelectParameters>
<asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
Name="AptId" />
</SelectParameters>
</asp:ObjectDataSource>



namespace BOL
{
public class Pics
{
private readonly string _conString;

public Pics()
{
_conString = ConfigurationManager.
ConnectionStrings["MyDataConnectionString"].ConnectionString;
}

public static void DeletePicsByApt(int AptID)
{
DBAccess db = new DBAccess(false);
db.CommandText = "DELETE FROM pics " +
"WHERE AptId='" + AptID.ToString() + "'";
}

public SqlDataReader GetPics(int AptID)
{
// Create Command
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM pics " +
"WHERE AptId=@AptID " +
"ORDER BY SeqNum ASC";

// Add Parameters
cmd.Parameters.AddWithValue("@AptId", AptID);

// Execute Comand
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

public void Update(int PicID, int SeqNum, String Title)
{
// Create Command
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE pics SET " +
"SeqNum=@SeqNum, " +
"Title=@Title " +
"WHERE PicID=@PicID";

// Add Parameters
cmd.Parameters.AddWithValue("@PicID", PicID);
cmd.Parameters.AddWithValue("@SeqNum", SeqNum);
cmd.Parameters.AddWithValue("@Title", Title);

// Execute Command
using (con)
{
con.Open();
cmd.ExecuteNonQuery();
}
}
 
The problem was that the line below needed to be removed:
DataObjectTypeName="BOL.Pics"


King Coffee said:
Hi,

Your help is greatly appreciated. The following code snippet displays the
Object Data OK... but if I try to update the edited fields SeqNum or Title
I get the following error message:

Could not find a property named 'SeqNum' on the type specified by the
DataObjectTypeName property in ObjectDataSource 'ObjectDataSource1'.

How do I define the Binding objects property names ??


<asp:GridView ID="GridView1" Runat="server"
DataSourceID="ObjectDataSource1"
AutoGenerateColumns="False" Width="100%" DataKeyNames="PicID" />
<Columns>
<asp:templatefield HeaderText="Sequence" ItemStyle-Width="50px" >
<itemtemplate>
<%#Eval("SeqNum")%>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtSeq" runat="server"
Text='<%#Bind("SeqNum")%>' />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtSeq"
Text="require" />
</edititemtemplate>
<itemstyle verticalalign="middle" width="50px" />
</asp:templatefield>
<asp:templatefield HeaderText="Title">
<itemtemplate>
<%#Eval("Title")%>
</itemtemplate>
<edititemtemplate>
<asp:TextBox ID="txtTitle" runat="server"
Text='<%#Bind("Title")%>' Width="300px" />
</edititemtemplate>
<itemstyle verticalalign="middle" width="50%" />
</asp:templatefield>
</Columns>



<asp:ObjectDataSource ID="ObjectDataSource1"
TypeName="BOL.Pics"
DataObjectTypeName="BOL.Pics"
SelectMethod="GetPics"
UpdateMethod="Update"
DeleteMethod="Delete"
Runat="server" >
<UpdateParameters>
<asp:Parameter Name="PicID", Type="Int32" />
<asp:Parameter Name="SeqNum", Type="Int32" />
<asp:Parameter Name="Title" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="PicID", Type="Int32" />
<asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
Name="AptId" />
</DeleteParameters>
<SelectParameters>
<asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
Name="AptId" />
</SelectParameters>
</asp:ObjectDataSource>



namespace BOL
{
public class Pics
{
private readonly string _conString;

public Pics()
{
_conString = ConfigurationManager.

ConnectionStrings["MyDataConnectionString"].ConnectionString;
}

public static void DeletePicsByApt(int AptID)
{
DBAccess db = new DBAccess(false);
db.CommandText = "DELETE FROM pics " +
"WHERE AptId='" + AptID.ToString() + "'";
}

public SqlDataReader GetPics(int AptID)
{
// Create Command
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT * FROM pics " +
"WHERE AptId=@AptID " +
"ORDER BY SeqNum ASC";

// Add Parameters
cmd.Parameters.AddWithValue("@AptId", AptID);

// Execute Comand
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

public void Update(int PicID, int SeqNum, String Title)
{
// Create Command
SqlConnection con = new SqlConnection(_conString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "UPDATE pics SET " +
"SeqNum=@SeqNum, " +
"Title=@Title " +
"WHERE PicID=@PicID";

// Add Parameters
cmd.Parameters.AddWithValue("@PicID", PicID);
cmd.Parameters.AddWithValue("@SeqNum", SeqNum);
cmd.Parameters.AddWithValue("@Title", Title);

// Execute Command
using (con)
{
con.Open();
cmd.ExecuteNonQuery();
}
}
 
Back
Top