遗忘海岸

江湖程序员 -Feiph(LM战士)

导航

Wince6.0 + xpsp3+VS2005的一些问题

1.连接WebService,需要.net framework2.0 sp2 才可以识别DataTable,

2.连接MSSQL2005 时报invoke 找不到dbnetlib.dll ,需要将到C:\Program Files\Microsoft Visual Studio 8\SmartDevices\SDK\SQL Server\Client\v2.0\wce500\armv4i下找到dbnetlib.dll,并将文件copy到CE中程序目录下,网上说的sql server目录下貌似找不到,这个dbnetlib.dll显示的是25KB作用

3.sqlite 需要保证程序中引用的dll与实际copy过去的dll一致,另外需要把SQLite.Interop.066.DLL也copy过去,
连接字符串是SQLiteConnection conn = new SQLiteConnection("Data Source=scan.db3;") 样子时,需要把数据库文件放在根目录.
sqlite的datetime类型的数据列在读取时会有问题,考虑用nvarchar替换

4.Sql Server Compact3.0 , 
下载http://support.microsoft.com/kb/920700 上的SDK安装,
需要把C:\Program Files\Microsoft SQL Server Compact Edition\v3.1\SDK\bin\wce500目录下的dll都Copy到服务wince6.0 上

  • Sqlceca30.dll
  • Sqlcecompact30.dll
  • Sqlceer30en.dll
  • Sqlceme30.dll
  • Sqlceoledb30.dll
  • Sqlceqp30.dll
  • Sqlcese30.dll
  • System.Data.SqlServerCe.dll

有时候sql语句写错了,但是报的错信息可能不是关于sql方面的,支持子查询,但是不支持";"分割的多个sql语句。
有些错误信息不资源文件没有,可以先安装
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\CompactFramework\WindowsCE\wce500\armv4\NETCFv2.wce5.armv4.cab
安装目录默认是Windows,可以尝试下更改目录到当前程序运行目录

 批量操作时可以使用下面代码:

View Code
            using (SqlCeConnection conn = new SqlCeConnection(ClientDB.ConnString))
            {
                conn.Open();
                string cmdText = @"Insert Into ScanStatus(LblSn,Status,Msg,AddTime)
                               Values(@LblSn,@Status,@Msg,@AddTime)";
                SqlCeCommand cmd = new SqlCeCommand(cmdText, conn);
                cmd.Parameters.AddRange(new SqlCeParameter[]{new SqlCeParameter("@LblSn", SqlDbType.NVarChar),
                                      new SqlCeParameter("@Status", SqlDbType.NVarChar),
                                      new SqlCeParameter("@Msg", SqlDbType.NVarChar),
                                      new SqlCeParameter("@AddTime", SqlDbType.DateTime)});
                cmd.Prepare();
                for (int i = 0; i < 500; i++)
                {
                    cmd.Parameters["@LblSn"].Value = "123" + i;
                    cmd.Parameters["@Status"].Value = ClientDB.C_ScanStatus_Success;
                    cmd.Parameters["@Msg"].Value = string.Empty;
                    cmd.Parameters["@AddTime"].Value = DateTime.Now;

                    cmd.ExecuteNonQuery();
                }
            }
            MessageBox.Show("OK!");

几段读写代码:

View Code
  using System.IO;
    using System.Reflection;
    public class ClientDB
    {
        /// <summary>
        /// 状态常量
        /// </summary>
        public static string C_ScanStatus_Success = "成功";
        public static string C_ScanStatus_NetException = "错误_网络";
        public static string C_ScanStatus_Exception = "错误";

        private static string _ConnString = @"Data Source={0}\{1}";
        private static string _Path=Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        public static string ConnString
        {
            get
            {

                return string.Format(_ConnString, _Path,DBFileName);
            }

        }
        private static string _DBFileName = @"scanInfo.sdf";
        public static string DBFileName
        {
            get
            {
                return _DBFileName;
            }
            set
            {
                _DBFileName = value;
            }
        }

        #region ScanInfo表
        public static int AddScanInfo(string lblSN, string empNo, string scanner, string fromStock, string toStock)
        {
            string cmdText = @"Insert Into ScanInfo(LblSn,EmpNo,ScanDate,Scanner,FromStock,ToStock,Name,Machine)
                                           Values(@LblSn,@EmpNo,@ScanDate,@Scanner,@FromStock,@ToStock,@Name,@Machine)";
            return ExcSql(cmdText, new SqlCeParameter("@LblSn", lblSN),
                            new SqlCeParameter("@EmpNo", empNo),
                            new SqlCeParameter("@ScanDate", DateTime.Now),
                            new SqlCeParameter("@Scanner", scanner),
                            new SqlCeParameter("@FromStock", fromStock),
                            new SqlCeParameter("@ToStock", toStock),
                            new SqlCeParameter("@Name", string.Empty),
                            new SqlCeParameter("@Machine", string.Empty));

        }
        public static int DelScanInfo(DateTime limitsDate)
        {

            string cmdText = @"Delete from ScanStatus 
                             Where LblSn in
                             ( 
                              Select LblSN From ScanInfo Where ScanDate<=@limitsDate
                             )";


            ExcSql(cmdText, new SqlCeParameter("@limitsDate", limitsDate));

            cmdText = "Delete From ScanInfo Where ScanDate<=@limitsDate";
            return ExcSql(cmdText, new SqlCeParameter("@limitsDate", limitsDate));

        }
        #endregion

        #region ScanStatus表
        public static int AddScanStatus(string lblSn, string msg, string status)
        {
            if (!string.IsNullOrEmpty(msg))
            {
                if (msg.Length > 50)
                {
                    msg = msg.Substring(0, 50);
                }
            }
            string cmdText = @"Insert Into ScanStatus(LblSn,Status,Msg,AddTime)
                               Values(@LblSn,@Status,@Msg,@AddTime)";
            return ExcSql(cmdText, new SqlCeParameter("@LblSn", lblSn),
                                  new SqlCeParameter("@Status", status),
                                  new SqlCeParameter("@Msg", msg),
                                  new SqlCeParameter("@AddTime", DateTime.Now));
        }

        #endregion

        #region 帮助
        public static DataSet LoadData(string cmdText)
        {
            using (SqlCeConnection conn = new SqlCeConnection(ConnString))
            {
                SqlCeCommand cmd = new SqlCeCommand(cmdText, conn);
                SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
        }
        public static int ExcSql(string cmdText)
        {
            using (SqlCeConnection conn = new SqlCeConnection(ConnString))
            {
                conn.Open();
                SqlCeCommand cmd = new SqlCeCommand(cmdText, conn);
                return cmd.ExecuteNonQuery();
            }
        }
        public static int ExcSql(string cmdText, params SqlCeParameter[] ps)
        {
            using (SqlCeConnection conn = new SqlCeConnection(ConnString))
            {
                conn.Open();
                SqlCeCommand cmd = new SqlCeCommand(cmdText, conn);
                foreach (SqlCeParameter p in ps)
                {
                    cmd.Parameters.Add(p);
                }
                return cmd.ExecuteNonQuery();
            }
        }
        #endregion
    }

5.Wince 6.0 中的程序与数据需要放到Application目录下,其他目录可能在系统冷启动后丢失数据

posted on 2012-12-11 13:23  遗忘海岸  阅读(1515)  评论(0编辑  收藏  举报