想要在dataGridView1显示数据库m136中sheet1表中的datatime和velocity两字段:调试没有错误,但为什么都不显示啊~!
我怀疑是不是下面语句放的顺序不对。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;namespace newform
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void tabPage1_Click(object sender, EventArgs e)
        {
            
        }        private void tabPage2_Click(object sender, EventArgs e)
        {
            string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=m136.mdb";
            string command = "select DateTime,Velocity from Sheet1 where Velocity in(select Velocity from Sheet1)";
            tie_dgv(connect, command);
        }         private void tie_dgv(string connect, string command)
        {
            string connectionstring = connect;
            string comandstring = command;
            OleDbDataAdapter dataAdapter = new OleDbDataAdapter(comandstring, connectionstring);//public OleDbDataAdapter(string selectCommandText选择语句, string selectConnectionString连接字符串);
            DataSet myDataSet = new DataSet();
            dataAdapter.Fill(myDataSet);
            this.dataGridView1.DataSource = myDataSet.Tables[0];//写DGV1控件的datasource属性。获取DGV所显示数据的数据源
        }         private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
         {
             
         }
        
    }
}

解决方案 »

  1.   

             string command = "select DateTime,Velocity from Sheet1 where Velocity in(select Velocity from Sheet1)";
       能查出数据吗
      

  2.   

    select DateTime,Velocity from Sheet1 where Velocity in(select Velocity from Sheet1这个sql太神奇了吧 你还不如直接写成
    select DateTime,Velocity from Sheet1
      

  3.   

    我用的是access。有什么不对的地方吗???
    string connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=m136.mdb";
                 string command = "select DateTime,Velocity from Sheet1 where Velocity in(select Velocity from Sheet1)";
                 tie_dgv(connect, command);
    以上这句写在什么地方啊?是
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
             {
             }
    或者是: private void tabPage2_Click(object sender, EventArgs e)
    {}
      

  4.   

    我想要直接打开tabPage2选项卡就显示数据。连接和显示代码是不是应该放在:
    private void tabPage2_Click(object sender, EventArgs e)
    {}
      

  5.   

    select [DateTime],[Velocity] from [Sheet1] where Velocity in (select Velocity from S[heet1])