VS2005之前一直没问题的,突然程序就不能运行了,错误是用户代码未处理OleDbException 5
$exception{"创建文件失败。"}System.Exception{System.Data.OleDb.OleDbException}ex{"创建文件失败。"}S...
$exception {"创建文件失败。"} System.Exception {System.Data.OleDb.OleDbException}
ex {"创建文件失败。"} System.Exception {System.Data.OleDb.OleDbException}
注:我的数据源是Excel
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
/// <summary>
/// DBPFOperator 的摘要说明
/// </summary>
public class DBPFOperator
{
private static string CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\182c945404084d2\\D$\\Data\\MANUFACTURING LIST-PF-April2010.xls;Extended Properties=Excel 8.0;";
/**
* 根据sql得到DataSet
*/
public DBPFOperator()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static DataSet GetDataSet(string sql, string tableName)
{
DataSet ds = new DataSet();
OleDbConnection sqlConn = null;
try
{
sqlConn = new OleDbConnection(CONN_STRING);
OleDbDataAdapter sqlApt = new OleDbDataAdapter(sql, sqlConn);
sqlApt.Fill(ds, tableName);
return ds;
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConn.Close();
}
}
/**
* 执行SQL语句
* sql
*/
public static int ExecuteSQL(string sql)
{
OleDbConnection sqlConn = null;
try
{
sqlConn = new OleDbConnection(CONN_STRING);
OleDbCommand sqlCmd = new OleDbCommand(sql, sqlConn);
sqlConn.Open();
return sqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConn.Close();
}
}
} 展开
ex {"创建文件失败。"} System.Exception {System.Data.OleDb.OleDbException}
注:我的数据源是Excel
代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.OleDb;
/// <summary>
/// DBPFOperator 的摘要说明
/// </summary>
public class DBPFOperator
{
private static string CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\182c945404084d2\\D$\\Data\\MANUFACTURING LIST-PF-April2010.xls;Extended Properties=Excel 8.0;";
/**
* 根据sql得到DataSet
*/
public DBPFOperator()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static DataSet GetDataSet(string sql, string tableName)
{
DataSet ds = new DataSet();
OleDbConnection sqlConn = null;
try
{
sqlConn = new OleDbConnection(CONN_STRING);
OleDbDataAdapter sqlApt = new OleDbDataAdapter(sql, sqlConn);
sqlApt.Fill(ds, tableName);
return ds;
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConn.Close();
}
}
/**
* 执行SQL语句
* sql
*/
public static int ExecuteSQL(string sql)
{
OleDbConnection sqlConn = null;
try
{
sqlConn = new OleDbConnection(CONN_STRING);
OleDbCommand sqlCmd = new OleDbCommand(sql, sqlConn);
sqlConn.Open();
return sqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sqlConn.Close();
}
}
} 展开
3个回答
展开全部
GetDataSet(string sql, string tableName)
函数里少个sqlConn.Open();
函数里少个sqlConn.Open();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我建议你catch一下,看一下系统提示是什么错误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
芝麻开门
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询