OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "表格|*.xls";
string strPath;
if (ofd.ShowDialog() == DialogResult.OK)
{
try
{
strPath = ofd.FileName;
textBox1.Text = ofd.FileName;
string strCon = "provider=microsoft.jet.oledb.4.0;data source=" + strPath + ";extended properties=excel 8.0";
OleDbConnection Con = new OleDbConnection(strCon);
string strSql = "select id from [Sheet1$]";
OleDbCommand Cmd = new OleDbCommand(strSql, Con);
OleDbDataAdapter da = new OleDbDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds, "shyman");
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如何将dataGridView中id这一列数据在listbox中显示!
望高手帮助~~~~~~~~~~~~~
ofd.Filter = "表格|*.xls";
string strPath;
if (ofd.ShowDialog() == DialogResult.OK)
{
try
{
strPath = ofd.FileName;
textBox1.Text = ofd.FileName;
string strCon = "provider=microsoft.jet.oledb.4.0;data source=" + strPath + ";extended properties=excel 8.0";
OleDbConnection Con = new OleDbConnection(strCon);
string strSql = "select id from [Sheet1$]";
OleDbCommand Cmd = new OleDbCommand(strSql, Con);
OleDbDataAdapter da = new OleDbDataAdapter(Cmd);
DataSet ds = new DataSet();
da.Fill(ds, "shyman");
dataGridView1.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
如何将dataGridView中id这一列数据在listbox中显示!
望高手帮助~~~~~~~~~~~~~
this.LvProduct.Columns.Add("ID", 80, HorizontalAlignment.Center);
for(int i=0;i<ds.tables[0].count;i++)
{
ListViewItem item = new ListViewItem();
item.Text = ds.tables[0].Row[i].Cells["Id"].ToString();
LvProduct.Items.Add(item); }
LvProduct.GridLines = true;
LvProduct.View = View.Details;