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


C# SqlCeCommand.Dispose方法代码示例

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


在下文中一共展示了SqlCeCommand.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: Simpan

 //public void suaraOK()
 //{
 //    SoundPlayer playOK = new SoundPlayer(@"Backup\doorbell.wav");
 //    playOK.Play();
 //}
 //public void suaraError()
 //{
 //    SoundPlayer playError = new SoundPlayer(@"Backup\sirentone.WAV");
 //    playError.Play();
 //}
 public void Simpan()
 {
     //string Tanggal = DateTime.Now.ToString("dd/MM/yyyy");
     //string JamTanggal = DateTime.Now.ToString();
     try
     {
         SqlCeDataReader dr;
         SqlCeCommand cmd = new SqlCeCommand("Select * from AngkutTP where ScanBarcode ='" + textBoxBarcode.Text + "'", cKoneksi.Con);
         if (cKoneksi.Con.State == ConnectionState.Closed) { cKoneksi.Con.Open(); }
         dr = cmd.ExecuteReader();
         if (dr.Read())
         {
             //cSound.suaraError();
             MessageBox.Show("Duplicate Scan!!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
             dr.Close();
             cmd.Dispose();
             if (cKoneksi.Con.State == ConnectionState.Open) { cKoneksi.Con.Close(); }
             textBoxBarcode.Text = "";
             textBoxBarcode.Focus();
         }
         else
         {
             dr.Close();
             cmd.Dispose();
             string strSQL = "INSERT INTO AngkutTP VALUES('" + textBoxNoPolisi.Text + "','" + textBoxNomorator.Text + "','" + textBoxNamaTP.Text + "','" + textBoxBarcode.Text + "',GetDate())";
             cQuery.Execute(strSQL);
             //cSound.suaraOK();
         }
     }
     catch (SqlCeException ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
     }
 }
开发者ID:exucupers,项目名称:PerhutTPTPK,代码行数:44,代码来源:FormTP_Angkut.cs

示例3: addToDatabase

 private void addToDatabase(string _user,string _pwd)
 {
     myConnection = default(SqlCeConnection);
        // DataTable dt = new DataTable();
     Adapter = default(SqlCeDataAdapter);
     myConnection = new SqlCeConnection(storagePath.getDatabasePath());
     myConnection.Open();
     myCommand = myConnection.CreateCommand();
     myCommand.CommandText = "INSERT INTO ["+storagePath.getUserTable()+"] ([username],[password]) VALUES  " +
         " ('" + _user
         + "','" + _pwd
         + "' ) ";
     myCommand.CommandType = CommandType.Text;
     try
     {
         myCommand.ExecuteNonQuery();
         myCommand.Dispose();
         MessageBox.Show("Username : " + _user + " and password : " + _pwd + " added sucessfully");
     }
     catch (Exception ex)
     {
         //MessageBox.Show(_id + " : " + _item + " : " + _name);
         myCommand.Dispose();
     }
     myConnection.Close();
 }
开发者ID:angpao,项目名称:iStore,代码行数:26,代码来源:frmUserList.cs

示例4: checkStoredata

        public Boolean checkStoredata()
        {
            bm = this.txtBom.Text.ToUpper();
            Boolean isCheck = false;
            myConnection = default(SqlCeConnection);
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            Adapter = default(SqlCeDataAdapter);
            myConnection = new SqlCeConnection(storagePath.getDatabasePath());
            myConnection.Open();
            myCommand = myConnection.CreateCommand();
            myCommand.CommandText = "SELECT [ID]  FROM [" + storagePath.getBomTable() + "] WHERE ID ='"
                + bm + "' ";

            myCommand.CommandType = CommandType.Text;

            Adapter = new SqlCeDataAdapter(myCommand);
            Adapter.Fill(dt);
            Adapter.Dispose();
            if (dt.Rows.Count > 0)
            {
                isCheck = true;

            }
            else
            {
                isCheck = false;
            }
            myCommand.Dispose();
            dt = null;
            myConnection.Close();
            return isCheck;
        }
开发者ID:angpao,项目名称:iStore,代码行数:33,代码来源:frmMain.cs

示例5: frmDetail_Load

        private void frmDetail_Load(object sender, EventArgs e)
        {
            myConnection = default(SqlCeConnection);
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            Adapter = default(SqlCeDataAdapter);
            myConnection = new SqlCeConnection(storagePath.getDatabasePath());
            myConnection.Open();
            myCommand = myConnection.CreateCommand();
            myCommand.CommandText = "SELECT [ID],[Job],[ItemId],[Qty],[Unit],[CheckedDateTime],[CheckedBy],[Checked]  FROM ["
                + storagePath.getStoreTable() + "] WHERE ID ='"
                + bm + "' and Job='" + jb + "' and ItemId = '" + item + "' and Checked='true'";

            myCommand.CommandType = CommandType.Text;

            Adapter = new SqlCeDataAdapter(myCommand);
            Adapter.Fill(ds);
            Adapter.Dispose();
            if (ds.Tables[0].Rows.Count > 0)
            {
                //isCheck = true;
                this.txtItem.Text = ds.Tables[0].Rows[0]["ItemId"].ToString();
                this.txtCheckedDateTime.Text = ds.Tables[0].Rows[0]["CheckedDateTime"].ToString();
                this.txtCheckedBy.Text = ds.Tables[0].Rows[0]["CheckedBy"].ToString();
            }
            else
            {
               // isCheck = false;
            }
            myCommand.Dispose();
            dt = null;
            myConnection.Close();
        }
开发者ID:angpao,项目名称:iStore,代码行数:33,代码来源:frmDetail.cs

示例6: nonQuery

        /// <summary>
        /// Returns the number of affected rows from the Non-Query (UPDATE-, INSERT- or DELETE-statement only)
        /// </summary>
        /// <param name="sqlString">The SQL</param>
        /// <returns></returns>
        public int nonQuery(string sqlString)
        {
            int numberOfRows = 0;

            SqlCeCommand sqlCommand = null;

            try
            {
                dbConnection.ConnectionString = global::Tekken5DarkRessurectionScoreKeeper.Properties.Settings.Default.TekkenScoreDBConnectionString;
                sqlCommand = new SqlCeCommand(sqlString, dbConnection);

                openConnection();
                numberOfRows = sqlCommand.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Database error (NonQuery)");
            }
            finally
            {
                closeConnection();
                sqlCommand.Dispose();
            }
            return numberOfRows;
        }
开发者ID:kenchic,项目名称:battleScoreKeeper,代码行数:30,代码来源:ManageDB.cs

示例7: excute

        /**
         *
         * 执行sql,包括 : 插入、更新、删除
         *
         * */
        public bool excute(string sql)
        {
            SqlCeCommand command = null;
            try
            {
                command = new SqlCeCommand();
                command.Connection = conn;
                command.CommandText = sql;
                command.Transaction = conn.BeginTransaction();
                if (-1 != command.ExecuteNonQuery())
                {
                    command.Transaction.Commit();
                    return true;
                }

                else
                    return false;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return false;
            }
            finally
            {
                if (command != null)
                    command.Dispose();
            }
        }
开发者ID:lishengtao,项目名称:Anli_Project,代码行数:34,代码来源:SqlCeDBAccess.cs

示例8: SelectUser

        public void SelectUser(int x)
        {
            try
            {
                byte count = 0;
                SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM Users", cKoneksi.Con);
                SqlCeDataReader dr;
                if (cKoneksi.Con.State == ConnectionState.Closed) { cKoneksi.Con.Open(); }
                dr = cmd.ExecuteReader();
                if (dr.Read()) { count = 1; } else { count = 0; }
                dr.Close(); cmd.Dispose(); if (cKoneksi.Con.State == ConnectionState.Open) { cKoneksi.Con.Close(); }
                if (count != 0)
                {
                    DataSet ds = new DataSet();
                    SqlCeDataAdapter da = new SqlCeDataAdapter("SELECT * FROM Users", cKoneksi.Con);
                    da.Fill(ds, "Users");
                    textBoxUser.Text = ds.Tables["Users"].Rows[x][0].ToString();
                    textBoxPass.Text = ds.Tables["Users"].Rows[x][1].ToString();
                    checkBoxTP.Checked = Convert.ToBoolean(ds.Tables["Users"].Rows[x][2]);
                    checkBoxTPK.Checked = Convert.ToBoolean(ds.Tables["Users"].Rows[x][3]);

                    ds.Dispose();
                    da.Dispose();
                }
                else
                {
                    MessageBox.Show("Data User Kosong", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
                    buttonClose.Focus();
                }
            }
            catch (SqlCeException ex)
            {
                MessageBox.Show(cError.ComposeSqlErrorMessage(ex), "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
            }
        }
开发者ID:exucupers,项目名称:PerhutTPTPK,代码行数:35,代码来源:FormMasterUser.cs

示例9: Login

 public void Login()
 {
     try
     {
         SqlCeDataReader dr;
         string sql = "SELECT * From Users cross join idhandheld where userid='" + textBoxuserid.Text + "' and password ='" + textBoxPassword.Text + "'";
         SqlCeCommand cmd = new SqlCeCommand(sql,cKoneksi.Con);
         if (cKoneksi.Con.State == ConnectionState.Closed) { cKoneksi.Con.Open(); }
         dr = cmd.ExecuteReader();
         if (dr.Read())
         {
             UserID = dr["Userid"].ToString();
             IDHH = dr["IDHH"].ToString();
             ClassUser.UserID = UserID.Trim();
             ClassUser.HandheldID = IDHH.Trim();
             TP = dr["TP"].ToString();
             TPK = dr["TPK"].ToString();
             dr.Close();
             cmd.Dispose();
             if (cKoneksi.Con.State == ConnectionState.Open) { cKoneksi.Con.Close(); }
             cekrole();
         }
         else
         {
             if (cKoneksi.Con.State == ConnectionState.Open) { cKoneksi.Con.Close(); }
             dr.Close();
             cmd.Dispose();
             MessageBox.Show("Username / Password Salah", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
             textBoxuserid.Text = "";
             textBoxuserid.Focus();
             textBoxPassword.Text = "";
         }
         textBoxuserid.Text = "";
         textBoxuserid.Focus();
         textBoxPassword.Text = "";
     }
     catch (SqlCeException ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
     }
 }
开发者ID:exucupers,项目名称:PerhutTPTPK,代码行数:41,代码来源:FormLogin.cs

示例10: Cleanup

 /// <summary>
 /// Cleanup unsuccessfull test log entries from the database (tests which did fail anyway).
 /// </summary>
 /// <param name="testContext">The test context.</param>
 /// <remarks>Documented by Dev03, 2008-08-01</remarks>
 internal static void Cleanup()
 {
     using (SqlCeConnection connection = GetConnection())
     {
         connection.Open();
         SqlCeCommand command = new SqlCeCommand("DELETE FROM \"TestRunData\" WHERE stoptime IS NULL AND run_id = @runid", connection);
         command.Parameters.Add("@runid", SqlDbType.Int, 8);
         command.Parameters["@runid"].Value = TestRunId;
         command.ExecuteNonQuery();
         command.Dispose();
     }
 }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:17,代码来源:TestStopWatch.cs

示例11: checkOsallistujat

        /// <summary>
        /// Hakee tietokannasta osallistujien ID:T ja paivittaa onkoTyhja
        /// arvon osallistujien ID-listan pituudella. Arvoa tarvitaan
        /// evaamaan tai sallimaan paasy tulosten kirjaukseen 
        /// </summary>
        /// <param name="onkoTyhja"> arvo kertoo montako osallistujaa tietokannassa on </param>
        /// <returns></returns>
        public int checkOsallistujat(int onkoTyhja)
        {
            List<int> osallistujat = new List<int>();

            SqlCeCommand cmd = null;
            SqlCeDataReader rdr = null;
            bool ok = false;

            do
            {
                SqlCeConnection con = _connection;
                try
                {
                    if (con.State == ConnectionState.Closed)
                        con.Open();

                    string Sql = String.Format(" SELECT osallistujaID FROM Osallistuja");
                    cmd = new SqlCeCommand(Sql, con);

                    rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        osallistujat.Add(rdr.GetInt32(0));
                    }

                    onkoTyhja = osallistujat.Count();
                    Console.WriteLine("Osallistujien maara tietokannassa: " + onkoTyhja);
                }
                catch (SqlCeException ex)
                {
                    //ShowErrors(ex);
                    Console.WriteLine("VIRHEILMOITUS checkOsallistujat");
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                    rdr.Close();
                    cmd.Dispose();
                    ok = true;
                }

            } while (!ok);

            return onkoTyhja;
        }
开发者ID:Cubio,项目名称:Hauli,代码行数:56,代码来源:HauliDBHandler.cs

示例12: 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

示例13: buttonAngkutTP_Click

        private void buttonAngkutTP_Click(object sender, EventArgs e)
        {
            DialogResult pesan = MessageBox.Show("Anda Yakin ingin mengconvert data ini?", "Konfirmasi", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
            if (DialogResult.OK == pesan)
            {
                //convert
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    byte count = 0;
                    SqlCeCommand cmd = new SqlCeCommand("SELECT * FROM AngkutTP", cConnection.Con);
                    SqlCeDataReader dr;
                    if (cConnection.Con.State == ConnectionState.Closed) { cConnection.Con.Open(); }
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        count = 1;
                    }
                    else
                    {
                        count = 0;
                    }
                    dr.Close();
                    cmd.Dispose();

                    if (cConnection.Con.State == ConnectionState.Open) { cConnection.Con.Close(); }
                    if (count != 0)
                    {
                        ConvertAngkutTP();

                        Cursor.Current = Cursors.Default;
                    }
                    else
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Tidak ada data Angkut TP", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
                    Cursor.Current = Cursors.Default;
                }

            }
        }
开发者ID:exucupers,项目名称:PerhutTPTPK,代码行数:47,代码来源:FormTP_Docking.cs

示例14: checkUser

        public bool checkUser(String username)
        {
            try
            {
                conn = new SqlCeConnection(Settings.Default.AccountsConnectionString);
                conn.Open();

                cmd = new SqlCeCommand("SELECT * FROM [Users] WHERE Username = @Username;", conn);
                cmd.Parameters.AddWithValue("@Username", username);

                SqlCeDataReader reader = cmd.ExecuteReader();
                cmd.Dispose();
                return reader.HasRows;
            }
            catch (Exception) { }

            return false;
        }
开发者ID:NeilKey,项目名称:ChatServer3AC,代码行数:18,代码来源:DbManagement.cs

示例15: Exec

 public static void Exec(string query, SqlCeConnection conn, Dictionary<string, object> parameters = null)
 {
     SqlCeTransaction trans = conn.BeginTransaction();
     using (SqlCeCommand com = new SqlCeCommand(query, conn))
     {
         com.Transaction = trans;
         if (parameters != null)
         {
             foreach (var element in parameters)
             {
                 com.Parameters.AddWithValue(element.Key, element.Value);
             }
         }
         com.ExecuteNonQuery();
         trans.Commit(CommitMode.Immediate);
         com.Dispose();
     }
 }
开发者ID:Zunderbird,项目名称:Library_CourseWork,代码行数:18,代码来源:SQL.cs


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