コード例 #1
0
ファイル: DBdb2.cs プロジェクト: eseawind/sac-mxny
        /// <summary>
        /// 将流文件以二进制形式存进数据库,执行此方法之前要确保存在记录,因为二进制文件只能以updata方式存储
        /// </summary>
        /// <param name="tableName">数据库表名称</param>
        /// <param name="tabCName">用于标示字段的列名称</param>
        /// <param name="tabName">用于标示字段的真实记录</param>
        /// <param name="fileCName">存储文件字段的列名称</param>
        /// <param name="fileBytes">要存储的文件流</param>
        /// <param name="errMsg">返回错误信息</param>
        /// <returns>返回是否成功</returns>
        static public bool RetBoolUpFile(string tableName, string tabCName, string tabName, string fileCName, byte[] fileBytes, out string errMsg)
        {
            errMsg = "";
            bool flag = false;

            if (fileBytes.Length > 0)
            {
                string sql = "update T_SYS_MENU set " + fileCName + "=? where " + tabCName + "='" + tabName + "'";

                OleDbConnection con = new OleDbConnection(DBdb2.SetConString());
                try
                {
                    con.Open();
                    OleDbCommand oledbcom = new OleDbCommand(sql, con);

                    oledbcom.Parameters.Add("?", fileBytes);

                    if (oledbcom.ExecuteNonQuery() > 0)
                    {
                        flag = true;
                    }

                    con.Close();
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                finally { con.Close(); }
            }
            return(flag);
        }
コード例 #2
0
ファイル: DBdb2.cs プロジェクト: eseawind/sac-mxny
        static public bool DownLoadXml(string fileID, string filePath)
        {
            bool   ret    = true;
            string errMsg = "";

            try
            {
                OleDbConnection db2conn = new OleDbConnection(DBdb2.SetConString());
                string          sqlstr  = "select * from T_SYS_MENU where T_XMLID='" + fileID + "'";
                OleDbCommand    db2cmd  = new OleDbCommand(sqlstr, db2conn);
                db2conn.Open();
                OleDbDataReader db2reader = db2cmd.ExecuteReader();
                string          FileName  = filePath;
                if (!db2reader.Read())
                {
                    FileName = "";
                }
                else
                {
                    byte[]     bytes = (byte[])db2reader["B_XML"];
                    FileStream fs    = new FileStream(FileName, FileMode.Create, FileAccess.Write);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Flush();
                    fs.Close();
                }
                db2reader.Close();
                db2cmd.Dispose();
                db2conn.Close();
            }
            catch (Exception ce)
            {
                errMsg = ce.Message;
                ret    = false;
            }
            return(ret);
        }