Click here to Skip to main content
16,022,798 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
<br />public int LoadByCategories(int categoriID)<br />            {<br />                  Connection.Open();<br />                  try<br />                  {<br />                        SqlCommand cmd = new SqlCommand();<br />                        cmd.CommandText = "exec GetBooksByCategory @ID";<br />                        cmd.Connection = Connection;<br />                        cmd.Parameters.Add(new SqlParameter("ID", categoriID));<br />                        return cmd.ExecuteNonQuery();<br />                  }<br />                  finally<br />                  {<br />                        Connection.Close();<br />                  }<br />            }<br />


after this Function raises Error

<br />DataBinding: 'System.Int32' does not contain a property with the name 'ID'. <br />


what's the problem?

Posted

1 solution

West1989 wrote:
try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "exec GetBooksByCategory @ID";
cmd.Connection = Connection;
cmd.Parameters.Add(new SqlParameter("ID", categoriID));
return cmd.ExecuteNonQuery();
}


You are doing wrong here. You are trying to execute Stored procedure ?
Look at this
<br />public int LoadByCategories(int categoriID)<br />            {<br />                  Connection.Open();<br />                  try<br />                  {<br />                        SqlCommand cmd = new SqlCommand();<br />                        cmd.CommandType = System.Data.CommandType.StoredProcedure;<br />                        cmd.CommandText="GetBooksByCategory";<br />                        cmd.Connection = Connection;<br />                        cmd.Parameters.Add(new SqlParameter("@ID", categoriID));<br />                        return cmd.ExecuteNonQuery();<br />                  }<br />                  finally<br />                  {<br />                        Connection.Close();<br />                  }<br />            }

Hope this will help you :)

 
Share this answer
 


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