110,500
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
}