110,571
社区成员
发帖
与我相关
我的任务
分享
string sql = "select UUID from [Sheet1$] where MAC地址='" + TT + "'";
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 excelread
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string sConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Sheet1.xlsx; Extended Properties='Excel 12.0;HDR=YES;IMEX=1';";//此连接可以操作.xls与.xlsx文
//String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + + "Extended Properties='Excel 8.0;HDR=YES;IMEX=1';";
OleDbConnection con = new OleDbConnection(sConnectionString);
con.Open();
string TT = textBox1.Text;
string sql = "select UUID from [Sheet1$] where MAC地址=" + "TT";
OleDbCommand cmd = new OleDbCommand(sql,con);
textBox2.Text = cmd.ExecuteScalar().ToString();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
}
}
我的代码是这样的,但是运行的时候很多问题