C#统计shp属性内容,求帮助,有详细解答

我想从listbox里选中的属性名称,在shp文件里查找并统计数据,并将结果输出到datagridview2中,程序出现错误,求解决

private void button3_Click(object sender, EventArgs e)
{
string table = dbfFileName;
string strConnection =
@"Dsn=Visual FoxPro Tables;sourcedb=" + table + ";sourcetype=DBF;exclusive=No;backgroundfetch=Yes;collate=Machine";

        //对于连接串,注意版本问题

        string strSelect = "SELECT * FROM  " + table;

        OdbcConnection thisConnection = new OdbcConnection(strConnection);

        thisConnection.Open();

        OdbcDataAdapter thisAdapter = new OdbcDataAdapter(strSelect, thisConnection);

        DataSet thisDataSet = new DataSet();

        try
        {

            thisAdapter.Fill(thisDataSet);

        }

        catch (Exception exec)
        {

            MessageBox.Show(exec.Message);

        }




        for (int i = 0; i < listBox1.Items.Count; i++)
        {
            OdbcConnection Connection = new OdbcConnection(strConnection);

            Connection.Open();
            string sql = "select sum(listBox1.Items[i].ToString()) from table ";
            OdbcDataAdapter da = new OdbcDataAdapter(sql, Connection);

            DataSet ds = new DataSet();
            da.Fill(ds);
            this.dataGridView2.DataSource = ds.Tables[0];
            Connection.Close();

        }


        thisConnection.Close();

    }

            ![图片说明](https://img-ask.csdn.net/upload/201512/31/1451553383_101520.png)

            ![图片说明](https://img-ask.csdn.net/upload/201512/31/1451553469_130779.png)

string table = dbfFileName;
包含完整路径看看,根据提示,现在你文件没有找到。

找到了,但是他不在我的datagridview里显示统计后的结果,是我sql语句有问题吗?

我个人认为你的数据库连接表的代码错误