【问题标题】:how to show table on asp.net(c#) when select id from table where color='blue'当从 color='blue' 的表中选择 id 时如何在 asp.net(c#) 上显示表
【发布时间】:2019-11-10 03:46:57
【问题描述】:

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

我有 color 类型是 varchar(4) 在我的 SQL 字符串连接中,它无法在我的代码上运行 在我的代码中显示颜色时看不到表格 错误部分=>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 它可以工作 如果是一串条件,请帮我解决它

【问题讨论】:

  • 替换字符串列无效

标签: c# sql string select connection-string


【解决方案1】:

SQL = "选择 o.DEPTNM 作为 NM,count(distinct p.id) 作为 A,cast(count(p.id) 作为 FLOAT)/nullif(count(o.id),0) 作为 B,count (当 o.color='" +blue+ "' 然后 p.id 结束时的特殊情况)作为 C from table1 as o left join table2 as p on p.id=o.idgroup by o.DEPTNM";

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-27
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    相关资源
    最近更新 更多