2017-06-06 50 views
-1

我遇到了一個問題:我不斷收到如下所示的消息,但添加按鈕正在工作(意味着它將數據添加到數據庫中)。爲什麼我不斷收到這條消息,但SQL語法正在工作

下面的錯誤出現在我每次按add按鈕時。我更新了代碼。這是現在的showlist功能。

代碼:

void Showlist() 
{ 
    string sql = "SELECT studentnumber AS 'Student Number', lastname AS 'Last Name', firstname AS 'First Name', middlename AS 'Middle Name', picture AS 'Picture', course AS 'Course', year AS 'Year', section AS 'Section', partylist AS 'Partylist', information AS 'Information', position 'Position', election 'Election', FROM candidates"; 
    MySqlDataAdapter adapter = new MySqlDataAdapter(sql, conn); 
    DataSet ds = new DataSet(); 
    adapter.Fill(ds, "candidates"); 
    dataGridView1.DataSource = ds; 
    dataGridView1.DataMember = "candidates"; 
} 
+2

什麼是錯誤? – adPartage

+2

因爲我們並沒有對你所說的錯誤(你沒有告訴我們)的錯誤隱晦,我們不知道我們怎麼能幫你... – elgonzo

+2

瘋狂的猜測? 'Showlist()'或'clear()'拋出異常。 – Crowcoder

回答

0

有SELECT語句的額外,只是From之前。

更改SQL選擇路線爲: -

string sql = "SELECT studentnumber AS 'Student Number', lastname AS 'Last Name', firstname AS 'First Name', middlename AS 'Middle Name', picture AS 'Picture', course AS 'Course', year AS 'Year', section AS 'Section', partylist AS 'Partylist', information AS 'Information' , position 'Position', election 'Election' FROM candidates"; 
+0

它現在工作。謝謝:) – Michelle

0

您從關鍵字之前收到此錯誤消息,因爲一個不必要的逗號 '':

...election 'Election', FROM candidates... 

下面是正確的版本的SQL語句:

"SELECT studentnumber AS 'Student Number', lastname AS 'Last Name', firstname AS 'First Name', middlename AS 'Middle Name', picture AS 'Picture', course AS 'Course', year AS 'Year', section AS 'Section', partylist AS 'Partylist', information AS 'Information' , position 'Position', election 'Election' FROM candidates" 
+0

它現在工作。非常感謝:) – Michelle

+0

米歇爾,如果對你有幫助,請務必分享你的正確答案。謝謝 –

相關問題