问题描述
请教大家:错误提示如下:System.threading.threadabortexception:在可以调用OLE之前,必须将当前线程设置为单线程单元(STA)模式。请确保您的Main函数带有STAThreadAttribute标志。只有将调试器附加到该进程才会引发此异常。Program.cs中的代码如下:namespaceDJNB.Order{staticclassProgram{///<summary>///应用程序的主入口点。///</summary>[STAThread]//[STAThreadAttribute]staticvoidMain(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);//Application.Run(newfrmOrdersRpt("DJNB","Orders","MAIN"));//Application.Run(newfrmOrderRequirePlan("DJNB","Orders","MAIN"));////Application.Run(newfrmOrdersList("DJNB","Orders","MAIN"));//frmOrdersList//Application.Run(newfrmOrderSet("DJNB","Orders","MAIN"));//frmOrdersList//Application.Run(newfrmOrderEmailSend("DJNB","Orders","MAIN"));//Application.Run(newfrmProductionSummary("DJNB","Orders","MAIN"));//Application.Run(newfrmSysOrder("DJNB","Orders","MAIN"));Application.Run(newfrmStockRestaurant("DJNB","Orders","MAIN"));}}}不知道问题出在哪?
解决方案
解决方案二:
板凳
解决方案三:
我是想将资料导出EXCEL或是由EXCEL导入DGV在打开文件以话框时出现此错误出错代码:try{System.Data.OleDb.OleDbConnectioncon=newSystem.Data.OleDb.OleDbConnection();OpenFileDialogopen=newOpenFileDialog();open.Title="打开";open.Filter=".xls|*.xls";stringfilename="";if(open.ShowDialog()==DialogResult.OK){filename=open.FileName;}if(filename==""||filename==null){return;}//stringstrConn="Provider=Microsoft.Jet.OLEDB.4.0;DataSource="+filename.Trim()+";ExtendedProperties='Excel8.0;HDR=NO;IMEX=1'";con.ConnectionString="Provider=Microsoft.Jet.OleDb.4.0;DataSource="+filename.Trim()+";ExtendedProperties='Excel8.0;HDR=NO;IMEX=1'";con.Open();stringsqlstr="select*from[餐订库存$]";System.Data.OleDb.OleDbDataAdapterda=newSystem.Data.OleDb.OleDbDataAdapter(sqlstr,con);DataTabledt=newDataTable();da.Fill(dt);cdgv.DataSource=dt;con.Close();}catch(Exceptionex){MessageBox.Show(ex.ToString());}此代码我以前用过的,没错误今天拿来用就错,导出也一样!
解决方案四:
什么错误?
解决方案五:
学习
解决方案六:
Application.Run(newfrmStockRestaurant("DJNB","Orders","MAIN"));换成Application.Run(newfrmStockRestaurant());你试试
解决方案七:
可能出现在OpenFielDialog上面,调试时可能会出现此错误,你直接在Debug或Release目录运行可能就会出现此错误了。如果真是这样,我也想知道原因?
解决方案八:
是,错误出在if(open.ShowDialog()==DialogResult.OK)我调试时出错误我干脆不调试了,做好后放入框架中去执行,OK,没问题奶奶的,搞不懂!