查询中的订单条款 [英] ORDER CLAUSE IN QUERY

查看:75
本文介绍了查询中的订单条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我在Windows窗体中必须自动生成唯一的Job代码.
我选择了从数据库添加的最后一行,并用一个递增jobpk(自动生成主键),并使用字符串代码进行连接.

我有以下代码,但是查询在
返回异常

 dAdapter.Fill(ds," );  

 ORDER BY子句中的语法错误.


我的代码是:

 公共  void  newjobecodenoget(){
           OleDbConnection oleDbConnection1 =  System.Data.OleDb.OleDbConnection(connString);
           oleDbConnection1.Open();


           字符串查询= " ;
           OleDbDataAdapter dAdapter =  OleDbDataAdapter(query,connString);


           DataSet ds =  DataSet();

           dAdapter.Fill(ds," );
            Int32  S =  int  .Parse(ds.Tables [ 0 ].Rows [ 0 ] [ 0 ].ToString());
           S ++;
            MessageBox.Show("  + S);
            字符串 jobcodeno = "  + S .ToString();
            txtjobcode.Text = jobcodeno.ToString();

       }


我在构造函数中调用此函数,并且正在使用Access数据库.
jobpk是长整数格式的主键.

谁能帮我解决我的错误?

我尝试在查询中对jobpk使用引号(''''),但结果相同

解决方案

如果我没记错的话,Access不知道LIMIT关键字.

而不是使用

 选择 jobpk  from  jobcodemastertable  BY  jobpk  1  


尝试使用

  SELECT   TOP   1  jobpk  FROM  jobcodemastertable  ORDER   BY  jobpk  DESC  



尝试此

 "  



我不确定我是否尝试在sqlserver 2005中使用,但

 "  


不起作用,但我可以使用

 "  


请尝试以下查询

字符串查询= "  





字符串查询= "  


Dear all,
I am doing a Windows Form where I had to auto generate a Job code which is unique.
This I had done by selecting the last row added from the database and incrementing jobpk(auto generating primary key) with one and concatenating with a string code.

I had code as below, but the query returns an exception at

dAdapter.Fill(ds, "tbljobrdataview");


Syntax error in ORDER BY clause.


My code is:

public void newjobecodenoget(){
           OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
           oleDbConnection1.Open();


           String query = "Select jobpk from jobcodemastertable ORDER BY jobpk DESC LIMIT 1";
           OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);


           DataSet ds = new DataSet();

           dAdapter.Fill(ds, "tbljobrdataview");
           Int32  S = int.Parse(ds.Tables[0].Rows[0][0].ToString());
           S++;
            MessageBox.Show("" +S);
            String jobcodeno = "NFT" + S.ToString();
            txtjobcode.Text = jobcodeno.ToString();

       }


I call this function at constructor and I am using Access database.
jobpk is primary key in long integer format.

Can anyone help to sort out my mistake?

I have tried using quotes('''') to jobpk in query but same result

解决方案

If I am not mistaken Access does not know the LIMIT keyword.

Instead of using

Select jobpk from jobcodemastertable ORDER BY jobpk DESC LIMIT 1


try using

SELECT TOP 1 jobpk FROM jobcodemastertable ORDER BY jobpk DESC


instead.


Try this

"Select Top(1) jobpk from jobcodemastertable ORDER BY jobpk DESC"



i''m not sure i try in sqlserver 2005 but

"Select jobpk from jobcodemastertable ORDER BY jobpk DESC LIMIT 1"


not work but i can use

"Select Top(1) jobpk from jobcodemastertable ORDER BY jobpk DESC"


Hi, try below query

String query = "Select Max(jobpk) from jobcodemastertable"



or

String query = "Select top 1 jobpk from jobcodemastertable order by jobpk DESC"


这篇关于查询中的订单条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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