string table = "(SELECT n_news_id, n_title, n_summary, n_context, n_type,n_source,n_url, n_class,"
            + " n_webtype, n_isShow,n_top,n_topimg, n_isImport, n_user, n_auditing, n_createtime, n_nums,"
            + " n_isImage, n_imageName, n_imageUrl, n_imageShow, n_state,n_impshow ,n_intone FROM n_news ) tableinfo";各位好:
    近今天读到这段代码,有些问题不太明白,向大家请教:
1)每行都加了双引号,是不是作用就是提示换行呢
2)这段代码是不是提示将n_news中信息放在table中,table就类似一个缓存的容器对吗~
3)在最后括号外面,一个tableinfo它在这段SQL之后,它又是做什么用的呢~
希望大家给我指点一下,自己看不明白,对于C#基础知识太缺乏了~

解决方案 »

  1.   

    2、table是string类型的,是指的这条sql语句。
    3、tableinfo是这条查询产生的表名
      

  2.   

    1)这里不是换行 这里只是让程序好看一点而已..没什么作用 
    2)和3) 这个最终语句是无法运行把(Select .... from n_news )tableinfo 外面应该还有其他语句..Table内存数据的表而已.这些东西和C#没什么关系 是SQL语句而已.
      

  3.   

    上面的语句应该不是一个SQL语句吧~它是什么表达方式呀~对数据库进行操作吗~
      

  4.   

    这一段应该是用在sql文中吧??引号是进行换行。
    table是个字符串,里面装的是一段sql语句,sql语句的意思就是:把从n_news 检索出来的信息,起别名tableinfo
      

  5.   

     
    确实存在其他语句,有的就省略了,后面有句这个
    sqlDataReader = dbconnection.GetDataReader("select * from " + table + " where n_news_id=" + id);
    table就是一个字符串类似与select n_title,n_summary from table  where ...中的字段(n_title,n_summary )吧,用table可以多次使用,不需要每次都输入那些字段名对吧~
    还有上面说到tableinfo是个别名,这个好像也不太理解呀~
      

  6.   

    它是将SQL语句在C#代码中用字符串形式表示,以便在C#中调用方法执行你调式一下就知道了,在C#代码中得到字符串变量table的值,然后再sql编辑器中执行就知道了,记得去掉那些引号
      

  7.   

    说明啊 就是个SQL语句啊
    LZ啊 TABLE 怎么会是容器啊 string 啊
      

  8.   

    table是个字符串形式的,明白了~
      

  9.   

      public News getNews(string webtype, string classinfo, string type)
            {
                try
                {
                    string sql = "select top 1 * from " + table + " where 1=1";
                    if (webtype != null && webtype.Length > 0)
                    {
                        sql = sql + " and n_webtype = '" + webtype + "' ";
                    }
                    if (classinfo != null && classinfo.Length > 0)
                    {
                        sql = sql + " and n_class = '" + classinfo + "' ";
                    }
                    if (type != null && type.Length > 0)
                    {
                        sql = sql + " and n_type = '" + type + "' ";
                    }
                    sql = sql + " and n_state= " + DictState.OPENING + " order by n_news_id desc ";                dbconnection = new DBConnection();
                    sqlDataReader = dbconnection.GetDataReader(sql);你好~那我想再问这个问题,这段C#中嵌入了SQL语句~也不太懂
    1)之前请教了大家,里面select Top 1是取出一条记录对吗,where 1=1 是这段代码永远为真,就执行下面的语句
    2)那下面的判断webtype ,classinfo,type,n_state 是不是假如不为空,就作为where 后面的参数呢~
      假如webtype Classinfo为真,其他两个为假,那么这个SQL语句就是
      select top 1 * from + table where webtype=“” and classinfo =“”
     还是  select top 1* from + table where webtype=“” and classinfo =“” and type="" and state="" 
    3)谁可以帮我把这个语句优化一下,我看的不太清楚~
      

  10.   

    怎么优化,写的挺明白了。
    根据不同条件,拼不通的sql语句啊