乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 语句将excle导入到sql时,excle里面的表单如果是数...-sql排序excel,sqlexcel

语句将excle导入到sql时,excle里面的表单如果是数...-sql排序excel,sqlexcel

作者:乔山办公网日期:

返回目录:excel表格制作


你好,看了你的截图,觉得你是把数据类型搞错了。
在Excel里面靠右显示的是数字型,靠左显示的是字符型,所以,在你的Excel中存储的第一列和第四列都是数值型的,这和你的数据库定义不符。所以你可以尝试调整一下Excel的字段属性。

--通过数据导入向导,可以看到这个表名前后加了个单引号

--我excel表格sheet的名字是 11 ,语句写成 ['11$'], 测试OK

select * from OpenDataSource('Microsoft.ACE.OLEDB.12.0', 
'Data Source=D:\book1.xlsx;Extended Properties="Excel 12.0;HDR=Yes;IMEX=1"')...['11$']


检查Excel对应的字段和表对应的字段,是否有表里字段不允许NULL的字段在Excel里对应的列有空

protected void Button1_Click(object sender, System.EventArgs e)
{
string XLS_Path="";
string XLS_Name = MakeFileName();
string fileExtName = "";
if(File1.PostedFile.ContentLength >0)
{
try
{
fileExtName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("."));
if(fileExtName!=".xls"||fileExtName.Length<1)
{
Response.Write( "<script language=javascript>alert('数据导入失败.可能是文件格7a686964616fe59b9ee7ad94333式或路径不正确!!!');</script>");
return;
}
File1.PostedFile.SaveAs(Server.MapPath("../uploadexcel/")+XLS_Name+fileExtName);
XLS_Path =Server.MapPath("../uploadexcel/")+ XLS_Name+fileExtName;
}
catch(Exception ex)
{
Response.Write(ex.ToString());
}
}
else
{
Response.Write( "<script language=javascript>alert('请选择文件后再上传!!!');</script>");
return;
}
string ConStr=System.Configuration.ConfigurationManager.AppSettings["ConnString"];
SqlConnection Conn=new SqlConnection(ConStr);
string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '"+XLS_Path+"'"+";Extended Properties=Excel 8.0";
OleDbConnection cnnxls = new OleDbConnection (mystring);
OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",cnnxls);
DataSet myDs =new DataSet();
try
{
myDa.Fill(myDs);
}
catch
{
Response.Write( "<script language=javascript>alert('数据导入失败,请检查!!');</script>");
return;
}
if(myDs.Tables[0].Rows.Count<=0)
{
Response.Write( "<script language=javascript>alert('文件中可能没有数据,请检查后重新导入!');</script>");
return;
}

int []zjid=new int[myDs.Tables[0].Rows.Count];
string strSql = "";
string CnnString="Provider=SQLOLEDB;"+ConStr;
OleDbConnection conn =new OleDbConnection(CnnString);
OleDbCommand myCmd =null;

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网