一个有关数据访问层的问题
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里却报错说查询语法无效