当前位置: 代码迷 >> C# >> 初学者有关问题:字符串拼接有关问题(1)
  详细解决方案

初学者有关问题:字符串拼接有关问题(1)

热度:15   发布时间:2016-05-05 02:39:47.0
菜鸟问题:字符串拼接问题(1)
这两天给高手们找了不少麻烦,先谢了!虽是菜鸟问题,但对本人来说却都是迈不过去的坎,得有高人拉一把才行。
请问:如何打印出OpenTable函数里面的sql变量(在第16行)呢?

public static DataTable OpenTable(string TableName, string[] col, string[] condition)
{
string tempsql="";
string tempsql2="";
            string sql = "";
for(int i=0;i<col.Length;i++)
{
tempsql+=col[i];
if(i<col.Length-1)tempsql+=",";
}
for(int i=0;i<condition.Length;i++)
{
tempsql2+=condition[i];
if(i<condition.Length-1)tempsql2+=" and ";
}
            sql = "select top 9 " + tempsql + " from " + TableName + " where " + tempsql2;

            OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
            dt = new DataTable();
            try
            {
                da.Fill(dt);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                da.Dispose();
            }
            return dt;
}

下面涵数提供参数:

public static DataTable CommentQuery(string channel, string lanmu) //channel为articles;lanmu为pe
        {
            string[] col ={ "id", "title", "update","hit" };
            string[] cod ={ "channel='" + channel+"'","lanmu='" + lanmu+"'"};

            return DBQuery.OpenTable("articles", col, cod);
        }

------解决思路----------------------
Console.WriteLine(sql);
Debug.WriteLine(sql);
textBox1.Text=sql;
...
------解决思路----------------------
什么叫如何打印呢?你要在哪里看到这个拼接好的sql?
  相关解决方案