您的位置:首页 > 其它

Excel数据连接字符串

2010-11-30 20:37 309 查看
真是郁闷,每次碰到Excel都需要找原来的源码,烦人,现在干脆记下了吧:

1. 只能查询


string excelconnstring = string.Format(

@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1};IMEX=1'",

Excelsource, "Yes");/* HDR=YES; 表示 带有表头,第一行作为字段名. IMEX=1 表示 把非字符型表格内容作为string来读取 */

//建立指向该Excel文件的数据库连接

OleDbConnection con = new OleDbConnection(excelconnstring);

2.既能添加也能查询


string excelconnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Excelsource + ";Extended Properties='Excel 8.0;'";

OleDbConnection excelconn = new OleDbConnection(excelconnstring);

3.操作Excel的不等于情况只能用'<>',不能用'!='

4.例:select distinct * from [Sheet1$]
"

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: