想要在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)
{
}
}
}
我怀疑是不是下面语句放的顺序不对。
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)
{
}
}
}
能查出数据吗
select DateTime,Velocity from Sheet1
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)
{}
private void tabPage2_Click(object sender, EventArgs e)
{}