我在c应用程序中遇到此错误,但找不到column2

zlwx9yxi  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(401)

大家好,我收到这个错误“找不到column2”我想把两个查询合并在一个数据库中插入数据一切都很完美,但我不知道为什么会出现这种类型的错误,我不知道如何解决请帮助我谢谢

Here is my code:

    string sqlCust21 = "SELECT Name,sum(CAST(ubl As int)) FROM payment WHERE dates <= '" + dateTimePicker1.Text + "' Group By union SELECT Name,sum(CAST(ubl As int)) FROM payment WHERE dates > '" + dateTimePicker2.Text + "' Group By Name";
                DataAccess.ExecuteSQL(sqlCust21);
                DataTable dtCust21 = DataAccess.GetDataTable(sqlCust21);
                MessageBox.Show(dtCust21.Rows[0][2].ToString());
9udxz4iz

9udxz4iz1#

后面缺少列名 GROUP BY .

string sqlCust21 = "SELECT Name,sum(CAST(ubl As int)) FROM payment WHERE dates <= '" + dateTimePicker1.Text + "' 
Group By name  --<-- this
union SELECT Name,sum(CAST(ubl As int)) FROM payment WHERE dates > '" + dateTimePicker2.Text + "' Group By Name";
hzbexzde

hzbexzde2#

datarowcollections基于0。试试这个

MessageBox.Show(dtCust21.Rows[0][1].ToString());

相关问题