为什么我一直收到此消息,但SQL语法正常

时间:2017-06-06 18:51:12

标签: c# mysql

我遇到了一个问题:我一直收到如下所示的消息,但添加按钮正在运行(意味着它正在向数据库添加数据)。

每次按下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 个答案:

答案 0 :(得分:0)

[[0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0] [0 0 0 0 0 0]] [[1 1 1 1 1 1] [1 1 1 1 1 1] [1 1 1 1 1 1] [1 1 1 1 1 1]] hello5 之前的select语句中还有一个,

将sql选择行更改为: -

From

答案 1 :(得分: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"