一个有关数据访问层的问题

copyhunter12 2010-09-10 02:45:34
pids是传进来的string pids数值是"0,4"
string[] arrpid = pids.Split(',');
List<Models.data_type> list = new List<Models.data_type>();
using (EntityConnection econ = new EntityConnection(conString))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select a.id,a.Meta_Description,a.ClassDir,a.ParentDir,a.TemplateID,a.state,a.Ext1,a.Ext2,a.Ext3,a.Ext4,a.title,a.pid,a.pids,a.Depth,a.Child,a.arrChildID,a.OrderID,a.Meta_Keywords from EduModels.data_Type as a");
strSql.Append(" where a.id in (");
for (int i = 0; i < arrpid.Length; i++)
{
strSql.Append(Convert.ToInt32(arrpid[i]));
if (i != arrpid.Length - 1)
{
strSql.Append(",");
}
}
strSql.Append(") and a.state=1");
econ.Open();
EntityCommand ecomm = new EntityCommand(strSql.ToString(), econ);
EntityDataReader reader = ecomm.ExecuteReader(CommandBehavior.SequentialAccess);

报错说时查询语法无效。, 附近 项 ',', 列 1, 列 227.
我的sql语句拼完显示出来是
select a.id,a.Meta_Description,a.ClassDir,a.ParentDir,a.TemplateID,a.state,a.Ext1,a.Ext2,a.Ext3,a.Ext4,a.title,a.pid,a.pids,a.Depth,a.Child,a.arrChildID,a.OrderID,a.Meta_Keywords from EduModels.data_Type as a where a.id in (0,4) and a.state=1

写到sql2005里没有问题,但是在vs里却报错说查询语法无效
...全文
50 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
copyhunter12 2010-09-10
  • 打赏
  • 举报
回复
你认为是什么问题
copyhunter12 2010-09-10
  • 打赏
  • 举报
回复
一样还是 EntityDataReader reader = ecomm.ExecuteReader(CommandBehavior.SequentialAccess);
这句报错,报错和上边一样
银狐被占用 2010-09-10
  • 打赏
  • 举报
回复
string[] arrpid = pids.Split(',');
换成下面这句
string[] arrpid = pids.Split(new char[] {','});

28,404

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧