winCE使用心得之二:使用sqlce

你要使用sqlce首先要检查sqlserver服务是否启动。

用VS2008创建项目时选智能设备(VS2010不支持WinCE),目标平台选winCE

                SqlCeConnection  conn = new SqlCeConnection(@"Data Source =\AppDatabase1.sdf");
                conn.Open();

                SqlCeCommand cmd = conn.CreateCommand();

                SqlCeTransaction tx = conn.BeginTransaction();

                cmd.Transaction=tx;
                foreach (MessageInfo mi in f_mi)
                {

                    cmd.CommandText = "insert into temp (s1, s2) values ('1', '0',)";
                    

                    cmd.ExecuteNonQuery();                  

                }
                tx.Commit();


                MessageBox.Show("成功!");
            }
            catch (Exception ex)
            {
               
                MessageBox.Show(ex.Message);

            }
            finally
            {
                conn.Close();
            }

 

你可能感兴趣的:(winCE使用心得之二:使用sqlce)