mjh1134391229 2015-12-31 09:27 采纳率: 100%
浏览 1469
已结题

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)
  • 写回答

3条回答 默认 最新

  • threenewbee 2015-12-31 12:40
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器