OleDBConnection连接字符串 [英] OleDBConnection Connection string
问题描述
当我尝试此代码OleDBConnection.open()
无效且未引发任何错误时,只需打开Windows窗体并说出任何内容即可看到messageBox try1,但程序未显示try2连接字符串中的错误是什么,请帮助我还尝试了excel 12.0,但它在References(Microsoft Excel 14.0对象库)的Excel 14.0中查找,并且该文件存在于c:\ product.xlsx
When I try this code OleDBConnection.open()
not work and didn't throw any error, just open windows form and say anything I see messageBox try1 but program didn't show try2 what is the wrong in my connection string please help I've tried also excel 12.0 but it looks in reference Excel 14.0 in References (Microsoft Excel 14.0 Object Library) and the file is exist in c:\product.xlsx
OleDbConnection conn_exel = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.12.0; Data Source=C:\product.xlsx; Extended Properties=""Excel 14.0;HDR=Yes;""");
conn_exel.Open();
MessageBox.Show("try2");
OleDbCommand command_exel = new OleDbCommand(@"SELECT * FROM [Sayfa1$] WHERE id = 1",conn_exel);
OleDbDataReader reader_exel = command_exel.ExecuteReader();
MessageBox.Show("try3");
while (reader_exel.Read())
{
MessageBox.Show(reader_exel.GetString(1));
}
conn_exel.Close();
推荐答案
尝试这样
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES";
"HDR =是;"表示第一行包含列名,而不是数据. "HDR =否;"表示相反.
"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite.
这篇关于OleDBConnection连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!