当前位置: 首页>>代码示例>>C#>>正文


C# System.Data.OleDb.OleDbDataAdapter.Dispose方法代码示例

本文整理汇总了C#中System.Data.OleDb.OleDbDataAdapter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.OleDb.OleDbDataAdapter.Dispose方法的具体用法?C# System.Data.OleDb.OleDbDataAdapter.Dispose怎么用?C# System.Data.OleDb.OleDbDataAdapter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.OleDb.OleDbDataAdapter的用法示例。


在下文中一共展示了System.Data.OleDb.OleDbDataAdapter.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadExcelFile

        //載入Excel檔案中成員資料
        public static DataTable LoadExcelFile(string strFilePath, string strSheetName)
        {
            System.Data.OleDb.OleDbConnection cn = new System.Data.OleDb.OleDbConnection();
            cn.ConnectionString = "Provider=MicroSoft.Jet.OLEDB.4.0;Data Source = " + strFilePath + "; Extended Properties ='Excel 8.0;'";
            cn.Open();

            System.Data.OleDb.OleDbDataAdapter da;
            da = new System.Data.OleDb.OleDbDataAdapter("Select * from [" + strSheetName + "$]", cn);

            DataTable dt = new DataTable();
            try
            {
                da.Fill(dt);
            }
            finally
            {
                da.Dispose();
            }
            return dt;
        }
开发者ID:YC00,项目名称:jsplumb-with-signalr,代码行数:21,代码来源:GroupManagement.aspx.cs

示例2: GetDataTable

        /// <summary>
        /// Run a transact SQL query against the database.
        /// </summary>
        /// <param name="sqlQuery">String with the SQL query (Select, etc).</param>
        /// <returns>The DataTable with the result set. Returns a New, empty DataTable if there are any exceptions.</returns>
        public System.Data.DataTable GetDataTable(string sqlQuery)
        {
            // Do not proceed if the database is not connected.
            if (this.IsConnected == false)
            {
                this.hasException = true;
                this.lastException = new System.Exception("You cannot query a database until you connect to it (ExecuteQuery(string). Connect first.");

                if (this.ThrowExceptions == true) throw this.lastException;

                return new System.Data.DataTable();
            }

            // Clear past exceptions
            this.hasException = false;

            /*
             * Switch to the appropriate database client and execute the query
             *
             * Create an adapter to run the SQL query
             * It was found some WFS Queries exceeded the default time out, so we bump up the command timeout
             * Fill the DataTable with the results of the SQL query
             * Dispose of the Adapter
             * Send the Adapter to Nothing
             * Return the DataTable
             */

            System.Data.DataTable output = new System.Data.DataTable();

            switch (this.DataClient)
            {
                case DatabaseClient.OleClient:

                    try
                    {
                        System.Data.OleDb.OleDbDataAdapter oleAdapter = new System.Data.OleDb.OleDbDataAdapter(sqlQuery, this.oleConn);
                        oleAdapter.SelectCommand.CommandTimeout = this.CommandTimeout;
                        oleAdapter.Fill(output);
                        oleAdapter.Dispose();
                        return output;
                    }
                    catch (Exception exception)
                    {
                        this.hasException = true;
                        this.lastException = exception;
                        if (this.ThrowExceptions == true) throw this.lastException;
                    }

                    break;

                case DatabaseClient.SqlClient:

                    try
                    {
                        System.Data.SqlClient.SqlDataAdapter sqlAdapter = new System.Data.SqlClient.SqlDataAdapter(sqlQuery, this.sqlConn);
                        sqlAdapter.SelectCommand.CommandTimeout = this.CommandTimeout;
                        sqlAdapter.Fill(output);
                        sqlAdapter.Dispose();
                        return output;
                    }
                    catch (Exception exception)
                    {
                        this.hasException = true;
                        this.lastException = exception;
                        if (this.ThrowExceptions == true) throw this.lastException;
                    }

                    break;

                default:
                    this.hasException = true;
                    this.lastException = new SystemException("The database client type entered is invalid (DataClient=" + this.DataClient.ToString() + ").");
                    if (this.ThrowExceptions == true) throw this.lastException;
                    break;
            }

            return new System.Data.DataTable();
        }
开发者ID:SimWitty,项目名称:SimWitty,代码行数:83,代码来源:Database.cs

示例3: PrepareDatabase


//.........这里部分代码省略.........
                        "VALUES ('" + NewDescription +
                        "', '" + R.CreatedDate +
                        "', 9" +
                        ", '" + R.DisplayName +
                        "', 15" +
                        "," + SessionID +
                        "," + Convert.ToInt32(R.IsDesktopCapture) +
                        "," + Convert.ToInt32(R.IsPrimaryCamera) +
                        "," + R.SizeOnDisk +
                        "," + R.PlayLength +
                        "," + Convert.ToInt32(R.HasAudio) +
                        "," + Convert.ToInt32(R.HasVideo) +
             						")";

                    try
                    {
                        CM.CommandText = sSQL;
                        CM.ExecuteNonQuery();
                    }
                    catch(System.Data.OleDb.OleDbException Err)
                    {
                        MessageBox.Show(Err.Message);
                        string peek = Err.Message;
                        return;
                    }
                    catch(Exception Err)
                    {
                        MessageBox.Show(Err.Message);
                        string sPeek = Err.Message;
                        return;
                    }
                }

                foreach(OCL.Note N in RS.AllVisibleNotes(frmParent.LUser))
                {
                    int NoteID = 0;
                    sSQL = "INSERT INTO tblNotes(SyncTime,Description,SessionId,Created) VALUES('" +
                        N.SyncTime + "','" + N.Description + "'," + SessionID + ",'" +
                        N.Created +"'" +
                        ")";
                    CM.CommandText = sSQL;
                    try
                    {
                        CM.CommandText = sSQL;
                        CM.ExecuteNonQuery();
                        CM.CommandText = "SELECT @@IDENTITY";
                        NoteID = (int)CM.ExecuteScalar();

                    }
                    catch(System.Data.OleDb.OleDbException Err)
                    {
                        MessageBox.Show(Err.Message);
                        string peek = Err.Message;
                        return;
                    }
                    catch(Exception Err)
                    {
                        MessageBox.Show(Err.Message);
                        string sPeek = Err.Message;
                        return;
                    }
                    OCL.Attachments FileAttachments = N.AllVisibleAttachments(frmParent.LUser);
                    foreach(OCL.Attachment A in FileAttachments)
                    {
                        sSQL = "INSERT INTO tblAttachments(OriginalName,StoredName,NoteId,Created,FileSize) VALUES(" +
                            " '" + A.OriginalName + "','" + A.StoredName +
                            "'," + NoteID.ToString() +
                            ",'" + A.Created + "'" +
                            "," + A.FileSize +
                            ")";
                        CM.CommandText = sSQL;
                        try
                        {

                            CM.ExecuteNonQuery();
                        }
                        catch(System.Data.OleDb.OleDbException Err)
                        {
                            MessageBox.Show(Err.Message);
                            string peek = Err.Message;
                            return;
                        }
                        catch(Exception Err)
                        {
                            MessageBox.Show(Err.Message);
                            string sPeek = Err.Message;
                            return;
                        }
                    }
                }
            }
            DA.Dispose();
            DT.Dispose();
            CM.Dispose();
            #endregion

            AC.Close();
            AC.Dispose();
            System.Threading.Thread.SpinWait(500000);
        }
开发者ID:CarverLab,项目名称:Oyster,代码行数:101,代码来源:frmHardDisc.cs


注:本文中的System.Data.OleDb.OleDbDataAdapter.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。