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

问题描述

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

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

 dAdapter.Fill(ds,"  tbljobrdataview" );  

 ORDER BY子句中的语法错误.


我的代码是:

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


           字符串查询= " 从jobcodemastertable中选择jobpk ORDER BY jobpk DESC LIMIT 1";
           OleDbDataAdapter dAdapter =  OleDbDataAdapter(query,connString);


           DataSet ds =  DataSet();

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

       }


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

谁能帮我解决我的错误?

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

解决方案




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

解决方案




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

10-11 13:19