繁体   English   中英

从color ='blue'的表中选择ID时,如何在asp.net(c#)上显示表

[英]how to show table on asp.net(c#) when select id from table where color='blue'

当我的SQL字符串带有条件字符串时,我无法在asp.net的Grid-view上显示我的表

我在SQL字符串连接中有类型为varchar(4)的颜色 ,它无法在我的代码上工作,当我的代码中的颜色错误时我看不到表格=> color'“ + blue +”'它不起作用

 protected void BindData()
    {     
        DataSet ds;
        string SQL = "";




        SQL = ("select  id from table where color='"+blue+"'");
        ds = CreateDataSource(string.Format("exec P_PageData '{0}',{1},{2}", SQL, this.SplitPage1.CurrentPage, this.SplitPage1.PageSize));
        if (ds != null && ds.Tables.Count == 3)
        {
            this.SplitPage1.CurrentPage = Convert.ToInt32(ds.Tables[1].Rows[0]["CurPage"]);
            this.SplitPage1.TotalRecorder = Convert.ToInt32(ds.Tables[1].Rows[0]["Total"]);
            this.rptPremissionList.DataSource = ds.Tables[2];
            this.rptPremissionList.DataBind();
        }

    }

如果我将代码中的blur(string)替换为其他INT column则它不起作用,它可以工作,如果它是条件字符串,请帮助我如何解决它

SQL =“选择o.DEPTNM作为NM,选择count(distingt p.id)作为A,cast(count(p.id)AS FLOAT)/ nullif(count(o.id),0)作为B,count(distinct case当o.color ='“ + blue +”'然后p.id结束)时,来自table1的C作为o左连接table2作为o.DEPTNM在p.id = o.idgroup上的p“;

字符串需要用单引号引起来。

就是说,如果您使用参数化查询,就不会遇到这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM