问题描述
亲爱的所有人,
我在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 incrementingjobpk
(auto generating primary key) with one and concatenating with a string code.
I had code as below, but the query returns an exception atdAdapter.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('''') tojobpk
in query but same result解决方案
这篇关于查询中的订单条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!