0
你好我需要到Excel文件的連接做一個專欄中,我有這樣的代碼C#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 Excel = Microsoft.Office.Interop.Excel;
namespace Excel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\farm.xls';Extended Properties=Excel 8.0;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "Update [Sheet1$] set name = 'FARM GDL' where COMERCIO like 'FARM GUADALAJARA'";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
MessageBox.Show("Success");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
,但有什麼不工作的更新,當我運行它打開連接
我能做嗎?拜託,謝謝!
變化以這種方式連接字符串:
您是以x64還是x86運行? Jet只能在x86上工作,所以如果您以x64或(可能)作爲任何CPU運行,則連接將失敗。 – Andrew 2012-04-20 22:58:35
什麼是錯誤信息?不工作在這裏不是一個有用的信息。 – Steve 2012-04-20 23:01:34
¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿ Cómosabes que no funciona? 程序在例外中說了些什麼?你怎麼知道它不起作用? – CrazyDart 2012-04-20 23:02:16