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


C# SqlCeConnection类代码示例

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


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

示例1: MultiRSSqlCE

        public void MultiRSSqlCE()
        {
            if (File.Exists("Test.sdf"))
                File.Delete("Test.sdf");

            var cnnStr = "Data Source = Test.sdf;";
            var engine = new SqlCeEngine(cnnStr);
            engine.CreateDatabase();

            using (var cnn = new SqlCeConnection(cnnStr))
            {
                cnn.Open();

                cnn.Execute("create table Posts (ID int, Title nvarchar(50), Body nvarchar(50), AuthorID int)");
                cnn.Execute("create table Authors (ID int, Name nvarchar(50))");

                cnn.Execute("insert Posts values (1,'title','body',1)");
                cnn.Execute("insert Posts values(2,'title2','body2',null)");
                cnn.Execute("insert Authors values(1,'sam')");

                var data = cnn.Query<PostCE, AuthorCE, PostCE>(@"select * from Posts p left join Authors a on a.ID = p.AuthorID", (post, author) => { post.Author = author; return post; }).ToList();
                var firstPost = data.First();
                firstPost.Title.IsEqualTo("title");
                firstPost.Author.Name.IsEqualTo("sam");
                data[1].Author.IsNull();
                cnn.Close();
            }
        }
开发者ID:jdomzhang,项目名称:dapper-dot-net,代码行数:28,代码来源:Tests.cs

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

示例3: Commit

        public void Commit()
        {
            var connectionString = repository.GetConnectionString();
            using (var conn = new SqlCeConnection(connectionString))
            {
                conn.Open();

                using (var trans = conn.BeginTransaction())
                {
                    foreach (var command in commands)
                    {
                        try
                        {
                            SQLCeHelper.ResetParameterNullValue(command);
                            command.Transaction = trans;
                            command.Connection = conn;
                            command.ExecuteNonQuery();
                        }
                        catch (Exception e)
                        {
                            throw new KoobooException(e.Message + "SQL:" + command.CommandText, e);
                        }
                    }

                    trans.Commit();
                }
            }
            //Execute post content events
            foreach (var action in postActions)
            {
                action();
            }
            Clear();
        }
开发者ID:jason1234,项目名称:CMS,代码行数:34,代码来源:TextContentProvider.cs

示例4: GetApplicationId

        public static Guid GetApplicationId(string connectionString, string applicationName)
        {
            using (SqlCeConnection conn = new SqlCeConnection(connectionString))
                    {
                        using (SqlCeCommand cmd = new SqlCeCommand("SELECT ApplicationId FROM [aspnet_Applications] " +
                                            "WHERE ApplicationName = @ApplicationName", conn))
                        {
                            cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = applicationName;

                            conn.Open();
                            var applicationId = cmd.ExecuteScalar();
                            if (applicationId == null)
                            {
                                cmd.Parameters.Clear();
                                cmd.CommandText = "INSERT INTO [aspnet_Applications] (ApplicationId, ApplicationName, LoweredApplicationName, Description) VALUES (@ApplicationId, @ApplicationName, @LoweredApplicationName, @Description)";

                                applicationId = Guid.NewGuid();
                                cmd.Parameters.Add("@ApplicationId", SqlDbType.UniqueIdentifier).Value = applicationId;
                                cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 256).Value = applicationName;
                                cmd.Parameters.Add("@LoweredApplicationName", SqlDbType.NVarChar, 256).Value = applicationName.ToLowerInvariant();
                                cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 256).Value = String.Empty;

                                cmd.ExecuteNonQuery();
                            }
                            return (Guid)applicationId;

                        }
                    }
        }
开发者ID:raquelsa,项目名称:GalleryServerProWeb,代码行数:29,代码来源:SqlCeMembershipUtils.cs

示例5: InitTestSchema

        public void InitTestSchema()
        {
            var connStr = String.Format("Data Source = '{0}';", _testDb);
            using (var conn = new SqlCeConnection(connStr))
            {
                conn.Open();
                var command = new SqlCeCommand();
                command.Connection = conn;
                command.CommandText =
                    @"CREATE TABLE accel_data (
                                     id INT IDENTITY NOT NULL PRIMARY KEY,
                                     date DATETIME,
                                     Ax Float,Ay Float
                                     )";
                command.ExecuteNonQuery();

                command.CommandText = @"CREATE TABLE accel_params (
                                         id INT IDENTITY NOT NULL PRIMARY KEY,
                                         date DATETIME,
                                         sensorNumber smallint,
                                         offsetX Float,offsetY Float,
                                         gravityX Float,gravityY Float
                                     )";
                command.ExecuteNonQuery();

                command.CommandText = @"CREATE TABLE calibr_result (
                                         id INT IDENTITY NOT NULL PRIMARY KEY,
                                         accelDataId INT,
                                         accelParamsId INT
                                     )";
                command.ExecuteNonQuery();
            }
        }
开发者ID:pengwin,项目名称:AccelLib,代码行数:33,代码来源:TestDatabaseStub.cs

示例6: CreateInitialDatabaseObjects

        private static void CreateInitialDatabaseObjects(string connString)
        {
            using (SqlCeConnection conn = new SqlCeConnection(connString))
            {
                string[] queries = Regex.Split(NetworkAssetManager.Properties.Resources.DBGenerateSql, "GO");
                SqlCeCommand command = new SqlCeCommand();
                command.Connection = conn;
                conn.Open();
                foreach (string query in queries)
                {
                    string tempQuery = string.Empty;
                    tempQuery = query.Replace("\r\n", "");

                    if (tempQuery.StartsWith("--") == true)
                    {
                        /*Comments in script so ignore*/
                        continue;
                    }

                    _logger.Info("Executing query: " + tempQuery);

                    command.CommandText = tempQuery;
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (System.Exception e)
                    {
                        _logger.Error(e.Message);
                    }
                }
                conn.Close();
            }
        }
开发者ID:5dollartools,项目名称:NAM,代码行数:34,代码来源:CreateDatabase.cs

示例7: GetLogs

        public List<ErrorLog> GetLogs()
        {
            var result = new List<ErrorLog>();
            IEnumerable<string> logs;

            using (IDbConnection connection = new SqlCeConnection(Connection))
            {
                connection.Open();

                var query = _settingsManager.GetMaxNumberOfLogs() > -1 ?
                    string.Format("SELECT TOP {0} [AllXml] FROM [ELMAH_Error] ORDER BY [Sequence] DESC;", _settingsManager.GetMaxNumberOfLogs()) :
                    "SELECT [AllXml] FROM [ELMAH_Error] ORDER BY [Sequence] DESC";

                logs = connection.Query<string>(query);
            }

            foreach (var log in logs)
            {
                var errorLog = _parser.Parse(log);

                if (errorLog == null)
                {
                    _log.Error(string.Format("Failed to parse file: {0}", log));
                    continue;
                }

                result.Add(errorLog);
            }

            return result;
        }
开发者ID:sheryever,项目名称:elmah-log-analyzer-with-custom-data,代码行数:31,代码来源:SqlServerCompactErrorLogSource.cs

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

示例9: addIssuance

        //add issuance
        public bool addIssuance(DateTime issuance_date, string license_no, 
                                int violation_id, decimal price, int officer_id,
                                int issuance_status)
        {
            string sql_stmt;
            bool result = false;

            /**
            sql_stmt = "CREATE TABLE issuances " +
                           "(   " +
                           "    issuance_date datetime," +
                           "    license_no nvarchar(20)," +
                           "    violation_id int," +
                           "    price money," +
                           "    officer_id int," +
                           "    issuance_status int" +
                           ")   ";
            **/

            sql_stmt = "INSERT INTO issuances " +
                       "    (issuance_date,license_no,violation_id,price,officer_id,issuance_status) " +
                       "VALUES " +
                       "    (@id, @violation, @desc, @price, @last_mod)";

            SqlCeConnection conn = new SqlCeConnection(this.conn_string);
            conn.Open();

            try
            {
                SqlCeCommand cmd = conn.CreateCommand();
                cmd.CommandText = sql_stmt;

                cmd.Parameters["issuance_date"].SqlDbType = System.Data.SqlDbType.DateTime;
                cmd.Parameters["issuance_date"].Value = issuance_date;

                cmd.Parameters["license_no"].SqlDbType = System.Data.SqlDbType.NVarChar;
                cmd.Parameters["license_no"].Value = license_no;

                cmd.Parameters["violation_id"].SqlDbType = System.Data.SqlDbType.Int;
                cmd.Parameters["violation_id"].Value = violation_id;

                cmd.Parameters["price"].SqlDbType = System.Data.SqlDbType.Money;
                cmd.Parameters["price"].Value = price;

                //cmd.Parameters["officer_id"].SqlDbType = System.Data.SqlDbType.Int;
                //cmd.Parameters["officer_id"].Value = last_mod;

                cmd.Parameters["issuance_status"].SqlDbType = System.Data.SqlDbType.Int;
                cmd.Parameters["issuance_status"].Value = issuance_status;

                result = (cmd.ExecuteNonQuery() > 0);
            }
            catch (Exception err)
            {
                string msg = err.Message;
                result = false;
            }
            conn.Close();
            return result;
        }
开发者ID:arcknine,项目名称:MobileMonitor,代码行数:61,代码来源:DatabaseHandler.cs

示例10: connectToDatabase

        public void connectToDatabase()
        {
            mySqlConnection = new SqlCeConnection(@"Data Source=C:\University\Adv Software Engineering\Bug Tracker\BugTracker\BugTracker\BugDatabase.mdf");
            String selcmd = "SELECT BugID, LineStart, LineEnd, ProgrammerName, ClassName, MethodName, TimeSubmitted, ProjectName, Description FROM dbo ORDER BY TimeSubmitted";
            SqlCeCommand mySqlCommand = new SqlCeCommand(selcmd, mySqlConnection);

        }
开发者ID:MastaN81985,项目名称:BugTracker,代码行数:7,代码来源:Form1.cs

示例11: ExecuteSqlQuery

        public static DataTable ExecuteSqlQuery(string query, params SqlCeParameter[] sqlParams)
        {
            var dt = new DataTable();

            using (var conn = new SqlCeConnection(connStr))
            using (var cmd = new SqlCeCommand(query, conn))
            {
                try
                {
                    SqlCeEngine engine = new SqlCeEngine(conn.ConnectionString);
                    engine.Upgrade(conn.ConnectionString);
                }
                catch
                {
                }

                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddRange(sqlParams);

                conn.Open();
                dt.Load(cmd.ExecuteReader());
            }

            return dt;
        }
开发者ID:WakeDown,项目名称:ServiceCollector,代码行数:25,代码来源:Db.cs

示例12: GetTPunto

        public static TPunto GetTPunto(int id, SqlCeConnection conn)
        {
            TPunto p = null;
            using (SqlCeCommand cmd = conn.CreateCommand())
            {
                string sql = @"SELECT p.puntoId, p.nombre, p.edificioId, p.tag, p.cota, p.cubiculo, p.observaciones,
                                    e.nombre AS enombre, e.grupoId, g.nombre AS gnombre, p.csnmax, p.csnmargen, p.lastcontrol
                                    FROM puntos AS p
                                    LEFT OUTER JOIN edificios AS e ON e.edificioId = p.edificioId
                                    LEFT OUTER JOIN grupos AS g ON g.grupoId = e.grupoId
                                    WHERE p.puntoId= {0}";
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = String.Format(sql, id);
                using (SqlCeDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        p = GetPuntoFromDr(dr);

                    }
                    if (!dr.IsClosed)
                        dr.Close();
                }
            }
            return p;
        }
开发者ID:rafaelgr,项目名称:FalckCN50Sol,代码行数:26,代码来源:TPunto.cs

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

示例14: CreateSyncRepository

        public override void CreateSyncRepository()
        {
            string connectionString = "Data Source=\"" + _DbPath + "\";Max Database Size=128;Default Lock Escalation=100;";
            IDbConnection conn = new SqlCeConnection(connectionString);
            conn.Open();

            IDbTransaction t = conn.BeginTransaction();

            IDbCommand com = conn.CreateCommand();
            com.Transaction = t;

            StringBuilder createSyncItem = new StringBuilder();
            createSyncItem.Append("CREATE TABLE SyncItem").
                Append("(SyncID INT PRIMARY KEY IDENTITY, SyncFK INT, ClassID nvarchar(255), HashCode nvarchar(32), ").
                Append("SyncGuid UNIQUEIDENTIFIER, RowGuid UNIQUEIDENTIFIER)");
            com.CommandText = createSyncItem.ToString();
            com.ExecuteNonQuery();

            StringBuilder createFieldState = new StringBuilder();
            createFieldState.Append("CREATE TABLE FieldState").
                Append("(SyncFK INT, FieldName nvarchar(255), HashCode nvarchar(32), ").
                Append("RowGuid UNIQUEIDENTIFIER, PRIMARY KEY (SyncFK, FieldName))");
            com.CommandText = createFieldState.ToString();
            com.ExecuteNonQuery();

            t.Commit();

            conn.Close();
            conn.Dispose();
        }
开发者ID:Tobias-Schneider,项目名称:DiversityMobile,代码行数:30,代码来源:SyncDBManager.cs

示例15: SetBase

 public static void SetBase(bool Dummy,string path)
 {
     string constr = "Data Source = \"{0}\"; Password =\"pdabase\"";
     try
     {
         SqlCeConnection con = new SqlCeConnection(string.Format(constr, path));
         con.Open();
         //SqlCeCommand q=con.CreateCommand();
         SqlCeCommand q;
         if (Dummy)
         {
             q = new SqlCeCommand(string.Format(sql, 0), con);
             q.ExecuteNonQuery();
         }
         else
         {
             q = new SqlCeCommand(string.Format(sql, 1), con);
             q.ExecuteNonQuery();
         }
         con.Close();
     }
     catch (SqlCeException e)
     {
       Consoler(e.Message);
       Log(e.Message,logpath);
     }
 }
开发者ID:radtek,项目名称:pdaexport,代码行数:27,代码来源:Program.cs


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