关键字'order'附近的语法不正确 [英] Incorrect syntax near keyword 'order'

查看:78
本文介绍了关键字'order'附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 private void bind()
{
if(k ==2013​​)
{
RadioButtonList2.Visible = false;
}
其他
{
RadioButtonList1.Visible = false;
}
GridView1.Columns [6] .Visible = true;
DataSet dsDetails = new DataSet();
SqlConnection con = new SqlConnection(strCon);
SqlDataAdapter daDetails;
daDetails = new SqlDataAdapter(select row_number()over(order by id)as Sno,id,title,year,platform,domain,abstract from NewIEEE where year =+ k +order by year desc,sno ,con);
con.Open();

daDetails.Fill(dsDetails);
GridView1.DataSource = dsDetails; Cache [ds] = dsDetails;
GridView1.DataBind();
con.Close();
}







将出现错误

< pre lang =HTML> daDetails.Fill(dsDetails);





请帮我

解决方案

有...上述错误的至少2个原因:

1)错误的数据类型

如果字段是数字数据类型,查询:

 选择 row_number() over  order   by  id) as  Sno,id,title,year,platform,domain,abstract 
来自 NewIEEE
其中 year = ' 2013'
订单 desc ,sno



必须替换为:

 选择 row_number() order   by  id) as  Sno,id,title,year,platform,domain,abstract 
来自 NewIEEE
其中 year = 2013
订单 desc ,sno





2) k 变量是空(这是不可接受的):

 选择 row_number() over  order   by  id) as  Sno,id,title,year,platform,domain,abstract 
from NewIEEE
where year = ' '
顺序 desc ,sno


正如Maciej所说,k变量可能是一个空字符串,所以你的SQL读取了







 ... 其中年= 订单 < span class =code-keyword> by  ... 





通过在调试和查找中运行来轻松检查。



如果我真的,真的需要构建SQL字符串(不推荐)那么我首先使用字符串变量,然后使用它 - 这样就是易于调试,因为您可以设置断点&查看值,或将字符串写入输出窗口&看看。


你的K值包含空值。



  if (K!=  
{
// < span class =code-comment>您的查询

}







以便您可以避免传递Null值

private void bind()
    {
        if (k == "2013")
        {
            RadioButtonList2.Visible = false;
        }
        else
        {
            RadioButtonList1.Visible = false;
        }
        GridView1.Columns[6].Visible = true;
        DataSet dsDetails = new DataSet();
        SqlConnection con = new SqlConnection(strCon);
        SqlDataAdapter daDetails;
        daDetails = new SqlDataAdapter("select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract from NewIEEE where year=" + k + " order by year desc,sno", con);
        con.Open();

        daDetails.Fill(dsDetails);
        GridView1.DataSource = dsDetails; Cache["ds"] = dsDetails;
        GridView1.DataBind();
        con.Close();
    }




error will be occur in

daDetails.Fill(dsDetails);



pls help me

解决方案

There are at least 2 reasons of above error:
1) bad data type
If year field is numeric data type, the query:

select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year='2013'
order by year desc,sno


must be replaced with:

select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year=2013
order by year desc,sno



2) k variable is empty (which is inacceptable):

select row_number() over (order by id) as Sno,id,title,year,platform,domain,abstract
from NewIEEE
where year=''
order by year desc,sno


As Maciej says, the k variable is probably an empty string, so your SQL reads



... where year = order by ...



Easy to check this by running in debug and looking.

If I really, really need to build SQL strings (not recommended) then I do it to a string variable first, which i then use - that way it is easy to debug, as you can set a breakpoint & look at the value, or write the string out to the output window & take a look.


your K value Contain null value.

if(K!="")
{
//your Query

}




so that you can avoid passing Null values


这篇关于关键字'order'附近的语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆