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#基础知识太缺乏了~
+ " 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#基础知识太缺乏了~
3、tableinfo是这条查询产生的表名
2)和3) 这个最终语句是无法运行把(Select .... from n_news )tableinfo 外面应该还有其他语句..Table内存数据的表而已.这些东西和C#没什么关系 是SQL语句而已.
table是个字符串,里面装的是一段sql语句,sql语句的意思就是:把从n_news 检索出来的信息,起别名tableinfo
确实存在其他语句,有的就省略了,后面有句这个
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是个别名,这个好像也不太理解呀~
LZ啊 TABLE 怎么会是容器啊 string 啊
{
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)谁可以帮我把这个语句优化一下,我看的不太清楚~
根据不同条件,拼不通的sql语句啊