C# 查询EXCEL出了问题。。来帮忙解决下!!!
我想做个查EXCEL表的程序,但是当我用我输入的数据查询时总是查不到。麻烦路过的高手帮个忙。!运行的结果:
[img=http://photo.163.com/jackipzz/big/#aid=237894402&id=7605734691][/img]
using System;--------------------编程问答-------------------- private void timer1_Tick(object sender, EventArgs e)
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();
}
}
}
{
IDataObject data = Clipboard.GetDataObject();
dd = (string)data.GetData(DataFormats.Text);
textBox2.Text = dd;
}
你的这个time不设置停止吗? 无限循环?
不是很明白,帮你顶下吧,求楼下吧 --------------------编程问答-------------------- 我这个TIMER是不断来监听剪切板的。。 --------------------编程问答-------------------- 终于找到答案了!!! string strcom="select 单号 from [Sheet1$] where 姓名= '"+textBox2.Text.Trim()+"'";
查询的语句要这样处理下!!!晕。搞了一个上午。。谢谢啦!! --------------------编程问答--------------------
貌似这个sql跟你上面sql不一样,,查询条件和查询字段弄反了
补充:.NET技术 , C#