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


C# SqlCeConnection.Dispose方法代码示例

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


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

示例1: CreateDB

        /// <summary>
        /// Create the initial database
        /// </summary>
        private void CreateDB()
        {
            var connection = new SqlCeConnection(this.path);

            try
            {
                var eng = new SqlCeEngine(this.path);
                var cleanup = new System.Threading.Tasks.Task(eng.Dispose);
                eng.CreateDatabase();
                cleanup.Start();
            }
            catch (Exception e)
            {
                EventLogging.WriteError(e);
            }

            connection.Open();
            var usersDB =
                new SqlCeCommand(
                    "CREATE TABLE Users_DB("
                    + "UserID int IDENTITY (100,1) NOT NULL UNIQUE, "
                    + "UserName nvarchar(128) NOT NULL UNIQUE, "
                    + "PassHash nvarchar(128) NOT NULL, "
                    + "Friends varbinary(5000), "
                    + "PRIMARY KEY (UserID));",
                    connection);
            usersDB.ExecuteNonQuery();
            usersDB.Dispose();
            connection.Dispose();
            connection.Close();
        }
开发者ID:novaksam,项目名称:CIS499_C-_IM_Package,代码行数:34,代码来源:DBInteract.cs

示例2: btnDelete_Click

        private void btnDelete_Click(object sender, EventArgs e)
        {
            btnSave.Enabled = false;
            grbDeviceIP.Enabled = false;

            dataSourcePath = "Data Source = " + Application.StartupPath + @"\DeviceData.sdf";
            SqlCeConnection sqlConnection1 = new SqlCeConnection();
            sqlConnection1.ConnectionString = dataSourcePath;
            SqlCeCommand cmd = new SqlCeCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection = sqlConnection1;
            sqlConnection1.Open();
            try
            {
                cmd.CommandText = "DELETE FROM DeviceData WHERE DEVICE_IP='" + Global.selMechIp + "'";
                cmd.ExecuteNonQuery();

                cmd.CommandText = "DELETE FROM DeviceURL WHERE DEV_IP='" + Global.selMechIp + "'";
                cmd.ExecuteNonQuery();
            }
            catch { }
            sqlConnection1.Dispose();
            sqlConnection1.Close();
            fnGetIpsFronTable();
            btnDelete.Enabled = false;
            btnEdit.Enabled = false;

            txtDevIp.Text = "";
            txtDevNo.Text = "";
            txtDevPort.Text = "";
            Application.DoEvents();
        }
开发者ID:nagamani-relyon,项目名称:BMDevice_new,代码行数:32,代码来源:frmNewDevice.cs

示例3: Add

        public bool Add(string varekode, string kategori, decimal poeng, DateTime slutt, DateTime start)
        {
            if (CheckDuplicate(varekode, poeng, slutt, start))
                return false; // Denne varekoden finnes allerede

            try
            {
                var con = new SqlCeConnection(FormMain.SqlConStr);
                con.Open();
                using (SqlCeCommand cmd = new SqlCeCommand("insert into tblVinnprodukt(Avdeling, Varekode, Kategori, Poeng, DatoOpprettet, DatoExpire, DatoStart) values (@Val1, @val2, @val3, @val4, @val5, @val6, @val7)", con))
                {
                    cmd.Parameters.AddWithValue("@Val1", main.appConfig.Avdeling);
                    cmd.Parameters.AddWithValue("@Val2", varekode);
                    cmd.Parameters.AddWithValue("@Val3", kategori);
                    cmd.Parameters.AddWithValue("@Val4", poeng);
                    cmd.Parameters.AddWithValue("@Val5", DateTime.Now);
                    cmd.Parameters.AddWithValue("@Val6", slutt);
                    cmd.Parameters.AddWithValue("@Val7", start);
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
                con.Close();
                con.Dispose();

                return true;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
            }
            return false;
        }
开发者ID:tborgund,项目名称:kgsa,代码行数:32,代码来源:Vinnprodukt.cs

示例4: CreatePatchesTable

 static void CreatePatchesTable()
 {
     if (!File.Exists(AppDataFolderHelper.GetDBFile("GkJournalDatabase.sdf")))
         return;
     var connection = new SqlCeConnection(ConnectionString);
     var sqlCeCommand = new SqlCeCommand(
         "CREATE TABLE Patches (Id nvarchar(20) not null)",
         connection);
     connection.Open();
     sqlCeCommand.ExecuteNonQuery();
     connection.Close();
     connection.Dispose();
 }
开发者ID:saeednazari,项目名称:Rubezh,代码行数:13,代码来源:GKDBHelper.Patches.cs

示例5: AddPatchIndexToDB

 public static void AddPatchIndexToDB(string Index)
 {
     if (!File.Exists(AppDataFolderHelper.GetDBFile("GkJournalDatabase.sdf")))
         return;
     if (string.IsNullOrEmpty(Index))
         return;
     var connection = new SqlCeConnection(ConnectionString);
     var sqlCeCommand = new SqlCeCommand("Insert Into Patches (Id) Values (@p1)", connection);
     sqlCeCommand.Parameters.AddWithValue("@p1", (object)Index);
     connection.Open();
     sqlCeCommand.ExecuteNonQuery();
     connection.Close();
     connection.Dispose();
 }
开发者ID:saeednazari,项目名称:Rubezh,代码行数:14,代码来源:GKDBHelper.Patches.cs

示例6: IsPatchesTableExists

 static bool IsPatchesTableExists()
 {
     if (!File.Exists(AppDataFolderHelper.GetDBFile("GkJournalDatabase.sdf")))
         return false;
     var connection = new SqlCeConnection(ConnectionString);
     var sqlCeCommand = new SqlCeCommand(
         "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Patches'",
         connection);
     connection.Open();
     var reader = sqlCeCommand.ExecuteReader(CommandBehavior.CloseConnection);
     bool result = reader.Read();
     connection.Close();
     connection.Dispose();
     return result;
 }
开发者ID:saeednazari,项目名称:Rubezh,代码行数:15,代码来源:GKDBHelper.Patches.cs

示例7: PrekrsajnaForma

        public PrekrsajnaForma()
        {
            InitializeComponent();

            // Dohvat popisa prekršaja.
            SqlCeConnection conn = new SqlCeConnection(Program.ConnString);
            string sqlQry =
                "SELECT " +
                    "ID, " +
                    "Naziv " +
                "FROM " +
                    "Prekrsaj;";

            try
            {
                DataTable dt = new DataTable("Prekrsaji");
                SqlCeCommand cmd = new SqlCeCommand(sqlQry, conn);
                SqlCeDataAdapter da = new SqlCeDataAdapter(sqlQry, conn);

                conn.Open();
                da.Fill(dt);

                if (dt.Rows.Count > 0)
                {
                    lbxPrekrsaji.DataSource = dt;
                    //lbxPrekrsaji.Refresh();
                }
                else
                {
                    throw new Exception("WTF! (What a Terrible Failure). Katalog prekršaja je prazan!");
                }
                da.Dispose();
                cmd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                conn.Dispose();
            }
        }
开发者ID:Brumiko,项目名称:NovaPP,代码行数:47,代码来源:PrekrsajnaForma.cs

示例8: ClearAll

 public void ClearAll()
 {
     try
     {
         var con = new SqlCeConnection(FormMain.SqlConStr);
         con.Open();
         SqlCeCommand command = new SqlCeCommand("DELETE FROM tblVinnprodukt WHERE Avdeling = " + main.appConfig.Avdeling, con);
         command.ExecuteNonQuery();
         Log.n("Vinnprodukt listen er tømt.");
         con.Close();
         con.Dispose();
     }
     catch(Exception ex)
     {
         Log.Unhandled(ex);
     }
 }
开发者ID:tborgund,项目名称:kgsa,代码行数:17,代码来源:Vinnprodukt.cs

示例9: GetAllPatches

        static List<string> GetAllPatches()
        {
            if (!File.Exists(AppDataFolderHelper.GetDBFile("GkJournalDatabase.sdf")))
                return null;
            var connection = new SqlCeConnection(ConnectionString);
            var sqlCeCommand = new SqlCeCommand("SELECT * FROM Patches", connection);
            var patchIndexes = new List<string>();
            connection.Open();
            var reader = sqlCeCommand.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                patchIndexes.Add(reader.GetValue(0).ToString());
            }
            connection.Close();
            connection.Dispose();
			return patchIndexes;
        }
开发者ID:saeednazari,项目名称:Rubezh,代码行数:17,代码来源:GKDBHelper.Patches.cs

示例10: ExecuteNonQuery

        /// <summary>
        /// Executes a non-query on the test database.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <remarks></remarks>
        public static void ExecuteNonQuery(string query)
        {
            using (var conn = new SqlCeConnection(String.Format("Data Source = {0}", DbFileName)))
            {
                conn.Open();

                using (var command = conn.CreateCommand())
                {
                    command.CommandType = CommandType.Text;
                    command.CommandText = query;

                    command.ExecuteNonQuery();
                    command.Dispose();
                }
                conn.Close();
                conn.Dispose();
            }
        }
开发者ID:coding3d,项目名称:InstantRDF,代码行数:23,代码来源:Database.cs

示例11: btnDelete_Click

        private void btnDelete_Click(object sender, EventArgs e)
        {
            dataSourcePath = "Data Source = " + Application.StartupPath + @"\DeviceData.sdf";
            if (Global.selUrlIp != "" && Global.selURL != "")
            {
                SqlCeConnection sqlConnection1 = new SqlCeConnection();
                sqlConnection1.ConnectionString = dataSourcePath;
                SqlCeCommand cmd = new SqlCeCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.Connection = sqlConnection1;
                sqlConnection1.Open();

                cmd.CommandText = "DELETE FROM DeviceURL WHERE DEV_IP='" + Global.selUrlIp + "' AND DEV_URL='" + Global.selURL + "'";
                cmd.ExecuteNonQuery();

                sqlConnection1.Dispose();
                sqlConnection1.Close();
                frmDeviceURL_Load(null, null);
            }
        }
开发者ID:nagamani-relyon,项目名称:BMDevice_new,代码行数:20,代码来源:frmDeviceURL.cs

示例12: Init

        public void Init()
        {
            var engine = new SqlCeEngine(_connstr);
            if (System.IO.File.Exists(_dbFilename)) {
                System.IO.File.Delete(_dbFilename);
            }
            engine.CreateDatabase();

            _conn = new SqlCeConnection(_connstr);
            _conn.Open();

            var cmd = new SqlCeCommand("create table test_table (id int identity primary key, str nvarchar(100));", _conn);
            cmd.ExecuteNonQuery();
            cmd.Dispose();

            if (_conn != null) {
                _conn.Close();
                _conn.Dispose();
            }

            _indepDalc = new SqlCeDalc(_connstr);
        }
开发者ID:jweakley,项目名称:libMatt,代码行数:22,代码来源:DalcTest.cs

示例13: Add

        public bool Add(string nameEmail, string addressEmail, string typeEmail, bool quickEmail)
        {
            nameEmail = nameEmail.Trim();

            if (!IsValidEmail(addressEmail))
            {
                Log.n("E-post adressen er i feil format.");
                return false;
            }

            if (CheckDuplicate(addressEmail))
                return false; // Denne adresse finnes allerede

            try
            {
                var con = new SqlCeConnection(FormMain.SqlConStr);
                con.Open();
                using (SqlCeCommand cmd = new SqlCeCommand("insert into tblEmail(Name, Address, Type, Quick) values (@Val1, @val2, @val3, @val4)", con))
                {
                    cmd.Parameters.AddWithValue("@Val1", nameEmail);
                    cmd.Parameters.AddWithValue("@Val2", addressEmail);
                    cmd.Parameters.AddWithValue("@Val3", typeEmail);
                    cmd.Parameters.AddWithValue("@Val4", quickEmail);
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
                con.Close();
                con.Dispose();
                return true;
            }
            catch (Exception ex)
            {
                Log.Unhandled(ex);
                return false;
            }
        }
开发者ID:tborgund,项目名称:kgsa,代码行数:36,代码来源:Email.cs

示例14: Test

        public override void Test()
        {
            string testString = ToTestString();

            // Create a connection object
            SqlCeConnection connection = new SqlCeConnection();

            // Try to open it
            try
            {
                connection.ConnectionString = ToFullString();
                connection.Open();
            }
            catch (SqlCeException e)
            {
                // Customize the error message for upgrade required
                if (e.Number == m_intDatabaseFileNeedsUpgrading)
                {
                    throw new InvalidOperationException(Resources.SqlCeConnectionProperties_FileNeedsUpgrading);
                }
                throw;
            }
            finally
            {
                connection.Dispose();
            }
        }
开发者ID:kjbartel,项目名称:ConnectionDialog,代码行数:27,代码来源:SqlCeConnectionProperties.cs

示例15: Remove

 public bool Remove(string id)
 {
     try
     {
         int result = 0;
         var con = new SqlCeConnection(FormMain.SqlConStr);
         con.Open();
         using (SqlCeCommand com = new SqlCeCommand("DELETE FROM tblEmail WHERE Id = " + id, con))
         {
             result = com.ExecuteNonQuery();
         }
         con.Close();
         con.Dispose();
         if (result > 0)
             return true;
         else
             return false;
     }
     catch (Exception ex)
     {
         Log.Unhandled(ex);
         return false;
     }
 }
开发者ID:tborgund,项目名称:kgsa,代码行数:24,代码来源:Email.cs


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