コード例 #1
0
ファイル: DBsql.cs プロジェクト: eseawind/sac-hnss
        static public bool DownLoadXml(string fileID, string filePath)
        {
            bool   ret    = true;
            string errMsg = "";

            try
            {
                SqlConnection sqlconn   = new SqlConnection(DBsql.GetConnectionstr());
                string        sqlstr    = "select * from T_SYS_MENU where T_XMLID='" + fileID + "'";
                SqlCommand    sqlcmd    = new SqlCommand(sqlstr, sqlconn);
                SqlDataReader sqlreader = sqlcmd.ExecuteReader();
                string        FileName  = filePath;
                if (!sqlreader.Read())
                {
                    FileName = "";
                }
                else
                {
                    byte[]     bytes = (byte[])sqlreader["B_XML"];
                    FileStream fs    = new FileStream(FileName, FileMode.Create, FileAccess.Write);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Flush();
                    fs.Close();
                }
                sqlreader.Close();
                sqlconn.Close();
            }
            catch (Exception ce)
            {
                errMsg = ce.Message;
                ret    = false;
            }
            return(ret);
        }
コード例 #2
0
ファイル: DBsql.cs プロジェクト: eseawind/sac-hnss
        /// <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 + "=@xmlfile where " + tabCName + "='" + tabName + "'";

                SqlConnection sqlconn = new SqlConnection(DBsql.GetConnectionstr());
                try
                {
                    sqlconn.Open();
                    SqlCommand sqlcmd = new SqlCommand(sql, sqlconn);
                    sqlcmd.Parameters.Add("@xmlfile", fileBytes);
                    if (sqlcmd.ExecuteNonQuery() > 0)
                    {
                        flag = true;
                    }

                    sqlconn.Close();
                }
                catch (Exception ex)
                {
                    errMsg = ex.Message;
                }
                finally { sqlconn.Close(); }
            }
            return(flag);
        }