标题:c#中sql语句拼接问题
取消只看楼主
lukebc
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:3
帖 子:74
专家分:32
注 册:2009-8-18
结帖率:71.43%
 问题点数:0 回复次数:0 
c#中sql语句拼接问题
if request("bh")<>""then
if cond="" then
cond="编号 like '%" & trim(request("bh")) & "%'"
else
cond = cond & " AND 编号 like '%" & trim(request("bh")) & "%'"
end if
end if
if request("ckbh")<>""then
if cond="" then
cond="出库编号 like '%" & trim(request("ckbh")) & "%'"
else
cond = cond & " AND 出库编号 like '%" & trim(request("ckbh")) & "%'"
end if
end if
if request("clmc")<>"" then
If cond="" Then
cond="材料名称 like '%" & trim(request("clmc")) & "%'"
else
cond = cond & "and 材料名称 like '%" & trim(request("clmc")) & "%'"
end if
end if

上面是asp中的拼接方式,我要将它转换成c#中的拼接方式,但是我写的好像不对,谁能帮我改一改
以下是我写的C#的拼接方式
 string sql = "";
            string str = "";
            if (textBox1.Text != "")
            {
                str = "bh like '%" + textBox1.Text + "%'";
            }
            else
            { str = str + "and bh like '%" + textBox1.Text + "%'"; }

            if (textBox1.Text != "")
            {
                str = "mc like '%" + textBox2.Text + "%'";
            }
            else
            { str = str + "and mc like '%" + textBox2.Text + "%'"; }

            if (str != "")
            { sql = "select * from text1 where'" + str + "'"; }
            else { sql = "select * from text1"; }
            label1.Text = sql;

搜索更多相关主题的帖子: request sql语句 拼接 
2016-09-01 11:15



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-468357-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.912813 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved