绑定问题 [英] problem with Bind

查看:101
本文介绍了绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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?

推荐答案

West1989写道:
West1989 wrote:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆