上载Excel工作表 [英] uploading Excel sheet
问题描述
你好,我正在用后端mysql5.0编写一个Asp.net应用程序.
我有一个.xlsx文件,我必须上传该文件并将其读取到mysql表中.
任何人都有任意的代码.
我尝试过代码-
Hello i am writing a Asp.net application with backend mysql5.0
i have a .xlsx file which i have to upload and read the data into mysql table.
Any one have any simalar code.
i had tried code-
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Path + ";" +
"Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
using (OleDbConnection cn = new OleDbConnection(ConnectionString))
{
cn.Open();
DataTable dbSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);
如果(dbSchema == null || dbSchema.Rows.Count< 1)
}
但是我遇到了一个异常,例如找不到可安装的ISAM..
任何建议!!
DataTable dbSchema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dbSchema == null || dbSchema.Rows.Count < 1)
}
but i throughs an exception like Could not find installable ISAM..
Any suggestion !!
推荐答案
请从
下载文件 并安装"http://www.microsoft.com/zh-cn/download/details.aspx?id=13255".
please download the files from
"http://www.microsoft.com/en-us/download/details.aspx?id=13255" and install it.
尝试一下,
try this,
if (hdnImageValues.Value != "")
{
string filePath = @"D:\Images\" + hdnImageValues.Value;
string fileName = hdnImageValues.Value;
if (File.Exists(filePath))
{
FileStream fs = File.Open(filePath, FileMode.Open);
byte[] fsbyte = null;
fsbyte = new byte[fs.Length];
fs.Read(fsbyte, 0, Convert.ToInt32(fs.Length, null));
fs.Close();
Response.AddHeader("contentdisposition","attachment;filename=" + fileName);
Response.BinaryWrite(fsbyte);
Response.End();
}
}
这篇关于上载Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!