我想把excel导入到sqlserver中,在sqlserver中运行
select * into asd FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="D:\1234\13022.xls";User
ID=;Password=;Extended properties=Excel 5.0')...biao3$
可以成功的将D:\1234\13022.xls下的sheet (biao3$) 导入到表asd中但是我在C#程序中通过
SqlConnection sqlcon = new SqlConnection("Server=agrs-wangyunfei;database=identity;uid=sa;pwd=11111111");
sqlcon.Open();
string aaa = "select * into asd FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=\"D:\\1234\\13022.xls\";User ID=;Password=;Extended properties=Excel 5.0')...biao3$";
SqlCommand cmd = new SqlCommand(aaa, sqlcon);
cmd.ExecuteNonQuery();
运行到cmd.ExecuteNonQuery();
就会出错,错误信息如下
未处理 System.Data.SqlClient.SqlException
Message="链接服务器 \"(null)\" 的 OLE DB 访问接口 \"Microsoft.Jet.OLEDB.4.0\" 报错。提供程序未给出有关错误的任何信息。\r\n无法初始化链接服务器 \"(null)\" 的 OLE DB 访问接口 \"Microsoft.Jet.OLEDB.4.0\" 的数据源对象。"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=7399
Procedure=""
Server="agrs-wangyunfei"
State=1
StackTrace:
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 shujudaoru.Form1.createtable() 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Form1.cs:行号 95
在 shujudaoru.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Form1.cs:行号 28
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 shujudaoru.Program.Main() 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Program.cs:行号 17
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
各位大侠帮忙看一下,谢谢了
select * into asd FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source="D:\1234\13022.xls";User
ID=;Password=;Extended properties=Excel 5.0')...biao3$
可以成功的将D:\1234\13022.xls下的sheet (biao3$) 导入到表asd中但是我在C#程序中通过
SqlConnection sqlcon = new SqlConnection("Server=agrs-wangyunfei;database=identity;uid=sa;pwd=11111111");
sqlcon.Open();
string aaa = "select * into asd FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=\"D:\\1234\\13022.xls\";User ID=;Password=;Extended properties=Excel 5.0')...biao3$";
SqlCommand cmd = new SqlCommand(aaa, sqlcon);
cmd.ExecuteNonQuery();
运行到cmd.ExecuteNonQuery();
就会出错,错误信息如下
未处理 System.Data.SqlClient.SqlException
Message="链接服务器 \"(null)\" 的 OLE DB 访问接口 \"Microsoft.Jet.OLEDB.4.0\" 报错。提供程序未给出有关错误的任何信息。\r\n无法初始化链接服务器 \"(null)\" 的 OLE DB 访问接口 \"Microsoft.Jet.OLEDB.4.0\" 的数据源对象。"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=7399
Procedure=""
Server="agrs-wangyunfei"
State=1
StackTrace:
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 shujudaoru.Form1.createtable() 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Form1.cs:行号 95
在 shujudaoru.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Form1.cs:行号 28
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 shujudaoru.Program.Main() 位置 C:\Documents and Settings\Administrator\桌面\c#\shujudaoru\shujudaoru\Program.cs:行号 17
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
各位大侠帮忙看一下,谢谢了
解决方案 »
- provider: SQL Network Interfaces, error: 0
- c#.net dicom控件
- 做考试系统时遇到问题
- 急速求解
- 关于Socket的问题.高手来看看!~在线等
- 系统运行速度慢:公司刚完成一个系统的开发,运行了一个多月了感觉速度很慢很慢,求原因!
- 各位高手帮帮小弟--ComboBox数据绑定
- 请问用Matrix 的Scale执行缩放与Graphics的SScaleTransform有什么区别么,是不是可以实现相同的功能
- 关于日期类型的简单问题!(答对马上结帖)
- ListBox设置了MultiColumn=true,为什么还是不能选择多行?
- 哪位大侠能帮我回答一下下面的问题,非常感谢!
- 请教有关数据集的问题!
string sql="select * from [sheetname]"
我把sqlconnection改为了OledbConnection
就是全部通过OledbConnection链接excel和sql server,以前是通过sqlconnection链接sql server,OledbConnection链接access,这样导入数据就会产生以上的冲突,我把代码改了一下:
OleDbConnection con = new OleDbConnection("Provider=SQLOLEDB;data source=agrs-wangyunfei;initial catalog=identity;user id=sa;pwd=11111111");
con.Open();
string aaa = "select * into asd FROM OpenDataSource('Microsoft.Jet.OLEDB.4.0','Data Source=\"D:\\1234\\13022.xls\";User ID=;Password=;Extended properties=Excel 5.0')...biao3$";
OleDbCommand cmd=new OleDbCommand (aaa,con );
cmd.ExecuteNonQuery ();
MessageBox .Show ("ok");
这样就可以把D:\1234\13022.xls中的sheet biao3$转到sql server中的asd表中,结贴,第一次发帖,哈哈