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


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

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


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

示例1: GetExcelSheetNames

        private String[] GetExcelSheetNames(string excelFile, bool blnXlsx = false)
        {
            System.Data.OleDb.OleDbConnection objConn = null;
            System.Data.DataTable dt = null;

            try
            {
                String connString = null;
                if (blnXlsx)
                {
                    connString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + excelFile + ";Extended Properties=\"Excel 12.0 Xml;HDR=NO;IMEX=1\"";
                }
                else
                {
                    connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelFile + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";
                }

                objConn = new System.Data.OleDb.OleDbConnection(connString);
                objConn.Open();
                dt = objConn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);

                if (dt == null)
                {
                    return null;
                }

                String[] excelSheets = new String[dt.Rows.Count];
                int i = 0;

                foreach (DataRow row in dt.Rows)
                {
                    excelSheets[i] = row["TABLE_NAME"].ToString();
                    i += 1;
                }
                return excelSheets;
            }
            catch (Exception ex)
            {
                throw (new Exception("Cannot Read Excel Sheet Names -" + ex.Message));
            }
            finally
            {
                if (objConn != null)
                {
                    objConn.Close();
                    objConn.Dispose();
                }
                if (dt != null)
                {
                    dt.Dispose();
                }
            }
        }
开发者ID:yousuf84,项目名称:Project1,代码行数:53,代码来源:ExcelDataAccess.cs

示例2: isHomologyNote

 public int isHomologyNote(string Table, string term1, string term2, string Value1, string Value2)
 {
     string tem_sql = "";//定义字符串变量
     System.Data.OleDb.OleDbConnection tem_conn =
         new System.Data.OleDb.OleDbConnection(connstr);//连接数据库
     System.Data.OleDb.OleDbCommand tem_comm;//定义OleDbCommand类
     tem_conn.Open();//打开数据库的连接
     //设置SQL语句,查找要添加的记录
     tem_sql = "select top 1 * From " + Table + " where " + term1 + " = '" + 
         Value1 + "' and " + term2 + " = '" + Value2 + "'";
     tem_comm = new System.Data.OleDb.OleDbCommand(tem_sql, tem_conn);//执行SQL语句
     int RecordCount = 0;//定义变量
     if (tem_comm.ExecuteScalar() == null)//如果查询为空
         RecordCount = 0;
     else
         RecordCount = (int)tem_comm.ExecuteScalar();//返回查找结果的个数
     tem_conn.Close();//关闭连接
     tem_comm.Dispose();//释放资源
     tem_conn.Dispose();//释放资源
     return RecordCount;//返回查询记录数量
 }
开发者ID:mahuidong,项目名称:c-1200-II,代码行数:21,代码来源:Frm_Main.cs

示例3: Create


//.........这里部分代码省略.........

                        dtArchManual.Columns.Add("Fecha");

                        foreach (DataRow drFila in dtArchManual.Rows)
                        {
                            int iAño = 0;
                            int iMes = 0;
                            int iDia = 0;

                            int.TryParse(drFila[0].ToString(), out iAño);
                            int.TryParse(drFila[1].ToString(), out iMes);
                            int.TryParse(drFila[2].ToString(), out iDia);

                            if (iAño > 0 && iMes > 0 && iDia > 0)
                            {
                                DateTime tFecha = new DateTime(iAño, iMes, iDia);
                                drFila["Fecha"] = tFecha.Date.ToShortDateString();
                            }

                            if (drFila["Fecha"].ToString() == objRelevamiento.FechaFinal.ToShortDateString())
                            {
                                foreach (DataColumn dcColumna in dtArchManual.Columns)
                                {
                                    if (dcColumna.Ordinal > 2)
                                    {
                                        //CORREGIR SELECCION DE INSECTO
                                        Insectos objInsecto = (from obj in db.Insectos where obj.NombreCientifico == dcColumna.ColumnName select obj).FirstOrDefault();
                                        if (objInsecto != null)
                                        {
                                            int Cantidad = 0;
                                            int.TryParse(drFila[dcColumna.Ordinal].ToString(), out Cantidad);
                                            if (Cantidad > 0)
                                            {
                                                LecturasManuales objLecturasManuales = new LecturasManuales();
                                                objLecturasManuales.IdRelevamiento = objRelevamiento.IdRelevamiento;
                                                objLecturasManuales.IdInsecto = objInsecto.IdInsecto;
                                                objLecturasManuales.Cantidad = Cantidad;
                                                objLecturasManuales.IdEstado = 1;

                                                db.LecturasManuales.Add(objLecturasManuales);
                                            }
                                        }
                                    }
                                }
                                //db.SaveChanges();
                                break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (oCnn.State == ConnectionState.Open) oCnn.Close();
                    }

                    if (oDa != null) { oDa.Dispose(); }
                    if (oCnn != null) { oCnn.Dispose(); }

                    //var objRelevamiento2 = (from obj in db.Relevamientos select obj).OrderByDescending(i => i.IdRelevamiento).First();
                    foreach (string Linea in lineasArchAuto)
                    {
                        string[] arrDatos = Linea.Split(';');
                        if (arrDatos.Length > 1 && arrDatos[1].ToString() == "LECTURA")
                        {
                            Lecturas objLecturas = new Lecturas();
                            objLecturas.IdEstado = 1;
                            objLecturas.IdRelevamiento = objRelevamiento.IdRelevamiento;
                            objLecturas.Frecuencia = double.Parse(arrDatos[2], System.Globalization.CultureInfo.InvariantCulture);
                            objLecturas.Aleteos = int.Parse(arrDatos[3]);
                            objLecturas.FechaLectura = DateTime.Parse(arrDatos[0]);
                            db.Lecturas.Add(objLecturas);
                        }
                        else if (arrDatos.Length > 1 && arrDatos[1].ToString() == "ESTADO")
                        {
                            Monitoreos objMonitoreos = new Monitoreos();
                            objMonitoreos.IdEstado = 1;
                            objMonitoreos.IdRelevamiento = objRelevamiento.IdRelevamiento;
                            objMonitoreos.Humedad = double.Parse(arrDatos[3], System.Globalization.CultureInfo.InvariantCulture);
                            objMonitoreos.Temperatura = double.Parse(arrDatos[2], System.Globalization.CultureInfo.InvariantCulture);
                            objMonitoreos.Bateria = double.Parse(arrDatos[4], System.Globalization.CultureInfo.InvariantCulture);
                            objMonitoreos.FechaMonitoreo = DateTime.Parse(arrDatos[0]);
                            db.Monitoreos.Add(objMonitoreos);
                        }
                    }
                    db.SaveChanges();
                    return Redirect("~/Alarmas/GenerarAlarmas");
                }
                else
                {
                    return View();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
开发者ID:Huakus,项目名称:Halcon,代码行数:101,代码来源:RelevamientosController.cs

示例4: InsertData

        /// <summary>
        /// InsertData
        /// </summary>
        /// <param name="fileName">模板文件在服务器端的完全路径</param>
        /// <param name="theData"></param>
        private bool InsertData(string fileName, DataTable theData)
        {
            // connection use oledb
            DataTable dt = theData;
            string strConn = string.Format(CONNECTION_STRING_WRITE, fileName);
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn);
            System.Data.OleDb.OleDbCommand cmd = null;
            bool bRet = false;
            try
            {
                conn.Open();
                //cmd = new System.Data.OleDb.OleDbCommand("Create table [sheet1]([name] Text, [age] int, [phone] Text)", conn);
                //cmd.ExecuteNonQuery();
                string strSQL = InsertSQL;
                cmd = new System.Data.OleDb.OleDbCommand(strSQL, conn);
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    cmd.Parameters.Add(i.ToString(), System.Data.OleDb.OleDbType.VarChar);
                }

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        cmd.Parameters[j.ToString()].Value = dt.Rows[i][j].ToString();
                    }
                    cmd.ExecuteNonQuery();
                }
                bRet = true;
            }
            catch (Exception e2)
            {
                bRet = false;
            }
            finally
            {
                if (cmd != null)
                {
                    cmd.Dispose();
                }
                conn.Dispose();
            }

            return bRet;
        }
开发者ID:XiaoQiJun,项目名称:BPS,代码行数:50,代码来源:ExcelTemplate.cs

示例5: DoExport

        public static bool DoExport(ExcelXMLLayout layout)
        {
            try
            {
                System.Data.OleDb.OleDbConnection conn =
                    new System.Data.OleDb.OleDbConnection(DB.ExcelFile.MakeConnectionString(layout.solution.path));

                StringBuilder sb = new StringBuilder(1024 * 1024);
                try
                {
                    conn.Open();
                    System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(
                        DB.ExcelFile.MakeSelectString(layout), conn);

                    try
                    {
                        System.Data.OleDb.OleDbDataReader r = cmd.ExecuteReader();
                        sb.Append("<?xml version='1.0' encoding='utf-8'?>");
                        sb.Append("<dataroot>");
                        while (r.Read())
                        {
                            if (IsHeadRow(r, layout))
                            {
                                continue;
                            }
                            sb.AppendFormat("<{0}>", layout.name);
                            for (int i = 0; i < r.FieldCount; ++i)
                            {
                                if (layout.typed)
                                {
                                    sb.AppendFormat("<{0} type='{1}'>{2}</{0}>",
                                        layout[i].name, ExcelXMLLayout.Type2Int(layout[i].type), r[i].ToString());
                                }
                                else
                                {
                                    sb.AppendFormat("<{0}>{1}</{0}>", layout[i].name, r[i].ToString());
                                }
                            }
                            sb.AppendFormat("</{0}>", layout.name);
                        }
                        sb.Append("</dataroot>");
                        r.Dispose();
                    }
                    catch (Exception rErr)
                    {
                        lastError = string.Format("表格查询命令\r\n{0}", rErr.ToString());
                        cmd.Dispose();
                        conn.Close();
                        conn.Dispose();
                        return false;
                    }
                    cmd.Dispose();
                    conn.Close();
                    conn.Dispose();
                }
                catch (Exception connOpenErr)
                {
                    lastError = string.Format("表格打开失败\r\n{0}", connOpenErr.ToString());
                    conn.Dispose();
                    return false;
                }
                //System.Diagnostics.Debug.WriteLine(sb.ToString());

                try
                {
                    System.IO.TextWriter w = System.IO.File.CreateText(layout.path);
                    w.Write(sb.ToString());
                    w.Close();
                }
                catch (Exception wErr)
                {
                    lastError = string.Format("目标XML文件无法写入\r\n{0}", wErr.ToString());
                    return false;
                }

                return true;
            }
            catch (Exception outErr)
            {
                lastError = string.Format("Excel 无法打开\r\n{0}", outErr.ToString());
                System.Diagnostics.Debug.WriteLine(outErr.ToString());
            }
            return false;
        }
开发者ID:ialex32x,项目名称:iExcelExport,代码行数:84,代码来源:ExcelFile.cs

示例6: btnRun_Click


//.........这里部分代码省略.........

            try
            {
                //fox
                cnnFox = new System.Data.OleDb.OleDbConnection();
                cmdFox = new System.Data.OleDb.OleDbCommand();
                daFox = new System.Data.OleDb.OleDbDataAdapter();

                daSet = new DataSet();

                //mdb
                cnnJet = new System.Data.OleDb.OleDbConnection();
                cmdJet = new System.Data.OleDb.OleDbCommand();

                if (cnnFox.State == ConnectionState.Closed)
                {
                    cnnFox.ConnectionString = sCnnStrFox;
                    cnnFox.Open();
                }
                cmdFox.Connection = cnnFox;
                cmdFox.CommandType = CommandType.Text;
                cmdFox.CommandText = sSqlFox;

                daFox.SelectCommand = cmdFox;
                daFox.Fill(daSet);

                if (cnnJet.State == ConnectionState.Closed)
                {
                    cnnJet.ConnectionString = sCnnStrJet;
                    cnnJet.Open();
                }

                cmdJet.Connection = cnnJet;
                cmdJet.CommandType = CommandType.Text;
                cmdJet.CommandText = "delete from OHCINDEX";
                cmdJet.ExecuteNonQuery();

                    foreach (DataTable T in daSet.Tables)
                    {
                        foreach (DataRow R in T.Rows)
                        {
                            iTotalImg++;
                            sPagina = R["V1PG"].ToString().Trim();

                            if (sPagina != "99")
                            {
                                is99 = false;
                                iTotalExp++;
                            }
                            else
                            {
                                is99 = true;
                            }

                            if (is99 == false)
                            {

                                INSUREDID =   R["V1INSUREID"].ToString().Trim();
                                PROVIDERNPI = RB1500.Checked ? R["V133ANPI"].ToString().Trim() : R["V156NPI"].ToString().Trim();
                                SERVICEDATE = R["V1DATEFROM"].ToString().Trim();
                                NOMBREIMAGEN =  "D:\\OHC\\" + R["V0IFNAME01"].ToString().Trim();
                            }
                            else
                            {
                                NOMBREIMAGEN = "D:\\OHC\\" + R["V0IFNAME01"].ToString().Trim();
                            }
                            /*
                             *  InsuredId
                                ProviderNpi
                                ServiceDate
                                ImageFile
                             */
                            string sSqlJet = "insert into OHCINDEX VALUES('" + INSUREDID + "','" +
                                                                               PROVIDERNPI + "','" +
                                                                               SERVICEDATE + "','" +
                                                                               NOMBREIMAGEN + "')";

                            cmdJet.CommandText = sSqlJet.Trim();
                            cmdJet.ExecuteNonQuery();
                        }
                    }//end Loop

                //Close
                cnnFox.Close();
                cnnJet.Close();
                cnnJet.Dispose();
                cnnFox.Dispose();

                // Copy MDB .... //
                Program.copyImg(this.txtOutPut.Text.Trim(), sMdbPath, true, "*.mdb");
                MessageBox.Show("Total de Imagenes:\r" + iTotalImg.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show("Total de Record:\r" + iTotalExp.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                MessageBox.Show("Done .. \r:-) Lindo Dia ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:jlarapr,项目名称:INDICE-OHC,代码行数:101,代码来源:frmMain.cs

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