我試圖將.xlsx文件(MS Excel 2007)導入到數據庫(My SQL)中。 它的工作在我的本地PC而不是在應用程序IIS6將Excel導入到MySql中 - 外部表格未處於預期格式
這是從的try-catch子句
An external table is not in the expected format.
我已經安裝了Microsoft Access數據庫引擎拋出的錯誤消息下運行的服務器PC 2010可再發行版 和2007 Office System Driver在服務器PC中。
下面是代碼
private void vIPToolStripMenuItem_Click(object sender, EventArgs e)
{
fiDatabase = null;
ofdDatabase.Title = "Select VIP list to input";
ofdDatabase.Filter = "Excel Files|*.xlsx";
if (ofdDatabase.ShowDialog() == DialogResult.OK)
{
fiDatabase = new FileInfo(ofdDatabase.FileName);
if (fiDatabase.Exists)
{
DeleteVIPList();
lblDateCreated.Text = fiDatabase.CreationTime.ToShortDateString();
lblDatabase.Text = fiDatabase.Name;
lblLocation.Text = fiDatabase.DirectoryName;
lblSize.Text = String.Format("{0:0,0.0}", fiDatabase.Length) + " byte";
btnLoadDatabase.Visible = true;
file = new StreamReader(fiDatabase.FullName);
OleDbConnection theConnection =
new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\VIPLIST092211.xlsx;Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\";");
try
{
theConnection.Open();
OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", theConnection);
DataSet theDS = new DataSet();
DataTable dt = new DataTable();
theDataAdapter.Fill(dt);
theConnection.Close();
dgvCustomer.DataSource = dt.DefaultView;
lblRecord.Text = dgvCustomer.Rows.Count.ToString();
update = new Update();
update.connectionString = MyCon;
update.UpdateVIPList(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show("No Database Selected");
}
}
}
我,並在錯誤消息「theConnection.Open()」如果任何人有過這個問題,我 請分享解決方案。 謝謝。
你可以發佈你的UpdateVIPList方法。 – BizApps 2011-12-16 04:48:18