绑定问题 [英] problem with Bind
问题描述
<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?
推荐答案
try
{
SqlCommand cmd =新的SqlCommand();
cmd.CommandText ="exec GetBooksByCategory @ID";
cmd.Connection =连接;
cmd.Parameters.Add(新SqlParameter("ID" ,categoriID));
返回cmd.ExecuteNonQuery();
}
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 :)
这篇关于绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!