private void button2_Click(object sender, EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog1;
            openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Title = "选择 Shp 文件";
            openFileDialog1.Filter = "Shapefile (*.shp)|*.shp";
            if(openFileDialog1.ShowDialog()==DialogResult.OK)
            {
            textBox1.Text = openFileDialog1.FileName;
           }
        }
为什么openFileDialog1.ShowDialog方法会影响我之后代码的数据库的读取?使用该方法以后,数据库读取数据为0。我去掉.ShowDialog()之后数据库读取正常。

解决方案 »

  1.   

    看下你其他的代码是否有影响。
    比如说textBox1赋值以后引起了什么后果。
    不要去怀疑.net本身的问题。
      

  2.   

    除非你通过openfiledialog改变了文件名。
      

  3.   

    我试过把textbox1的值直接写死,一切正常。
    通过showdialog赋值以后,textbox1也有值。
      

  4.   

    如果说有一点影响的话,这个textbox1的值最后附给了一个封装好的属性,这个属性和数据库操作的方法同在一个class下面,但是相互独立
      

  5.   

    数据库操作和这里的赋值操作是无关的,这个textbox1的值最后附给了一个封装好的属性,这个属性和数据库操作的方法同在一个class下面,但是相互独立。数据库操作是通过调用C++写的dll,C#和C++都是32位,读完所需的数据以后,写进textbox1的那个文件。可是,现在直接读不出来了。
      

  6.   

    有这事?用ProcessMon或者其它跟踪工具看看进程和网络方面到底发生了什么。
      

  7.   

    还是没有解决,看了一下,只有DialogResult.OK成立的时候才会受影响,关闭文件选择窗口无影响。
      

  8.   

    因为System.Windows.Forms.OpenFileDialog会改变程序的执行路径。
    而你别的方法一定是用了执行路径的信息,所以会出错。
    总的来说,问题还是出在使用执行路径信息的地方,而不是OpenFileDialog这里。
      

  9.   

    我把相关代码都发上来好了
     private void button2_Click(object sender, EventArgs e)
            {
                System.Windows.Forms.OpenFileDialog openFileDialog1;
                openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Title = "选择 Shp 文件";
                openFileDialog1.Filter = "Shapefile (*.shp)|*.shp";
               if (openFileDialog1.ShowDialog()==DialogResult.OK)
               {
                   textBox1.Text = openFileDialog1.FileName;
               }
               
            }
    这是选择文件的button,选择完以后,点击另一个button开始运算private void button1_Click(object sender, EventArgs e)
            {
                button1.Enabled = false;
                textBox1.Enabled = false;
                button2.Enabled = false;
                this.WindowState = FormWindowState.Minimized;
                this.ShowInTaskbar = false;
                base.SetVisibleCore(false);
                Computation computation = new Computation();
                computation.FilePath = @textBox1.Text;
                computation.Previous = System.DateTime.Now;
                Thread.Sleep(60000);
                computation.Start();
            }实例computation的start方法,首先会从数据库读取数据,然后再调用刚才选择的文件进行计算。
     public void Start()
                {
                    while (true)
                    {
                        timea = System.Environment.TickCount;
                        timeTemp = System.DateTime.Now;                    using (GetGPSPoints getGPSPoint = new GetGPSPoints())
                        {
                            list = getGPSPoint.GetPointList(2013,7,15,18,40,20);
                        }                    using (NearestCalBatchPoint testpro = new NearestCalBatchPoint())
                        {
                            bool testbool = testpro.BatchPointsCal(filePath, ref list, (double)30 / 33 / 3600);
                            roadSpdIndexLength = testpro.featureClass.FeatureCount(null);
                        } 
    第一个using(){}里面就是数据库读取操作 第二using(){}里才会使用被赋值的filepath