C# 查询EXCEL出了问题。。来帮忙解决下!!!

jackipzz jackipzz 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想做个查EXCEL表的程序,但是当我用我输入的数据查询时总是查不到。麻烦路过的高手帮个忙。!
运行的结果:





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 自助单号
{
public partial class Form1 : Form
{
string dd ;
string path;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
timer1.Start();

}

private void button1_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection Conn = new
System.Data.OleDb.OleDbConnection
(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'");
string strcom="select 姓名 from [Sheet1$] where 单号= '"+dd+"'";
Conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter(strcom, Conn);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "[Sheet1$]");
// Clipboard.SetText(ds.Tables[0].Rows[0][0].ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
Conn.Close();
return;
}
dataGridView1.DataSource = ds.Tables[0];
Conn.Close();

}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void timer1_Tick(object sender, EventArgs e)
{
IDataObject data = Clipboard.GetDataObject();
dd = (string)data.GetData(DataFormats.Text);
textBox2.Text = dd;
}

private void button2_Click_1(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
path = ofd.FileName;
textBox1.Text = path;
}

private void button3_Click(object sender, EventArgs e)
{
Clipboard.Clear();
}
}
}

...全文
评论 4
收藏 已收藏
分享
返回顶部
jackipzz
C# 111,129 成员 642,540 内容