1.采用stream流形式写入:

    #region 数据流转换成blob类型数据写入数据库
static public bool StreamToBlob(ref Stream stream, OdbcConnection conn, string sTable, string sBlobField, string sIDName, string sIDValue)
{
if (null == conn || stream == null || sTable == "" || sBlobField == "" || sIDName == "" || sIDValue == "")
throw new NullReferenceException(); DataSet dataSet = null;
OdbcDataAdapter adapter = null;
byte[] buff = null;
DataRow row = null;
int iRtn = 0;
string sSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", sTable, sIDName, sIDValue); try
{
adapter = new OdbcDataAdapter(sSQL, conn);
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
dataSet = new DataSet(sTable);
OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter);
adapter.Fill(dataSet, sTable);
// read blob data from stream
// cause there is only one row, the index we need update is 0
int iCnt = dataSet.Tables[0].Rows.Count;
row = dataSet.Tables[sTable].Rows[0];
buff = new byte[stream.Length];
stream.Seek(0, SeekOrigin.Begin);
stream.Read(buff, 0, System.Convert.ToInt32(stream.Length));
// update table's blob field
row[sBlobField] = buff;
iRtn = adapter.Update(dataSet, sTable);
}
catch (Exception ee)
{
string err = ee.Message.ToString();
MessageBox.Show(ee.Message + ee.StackTrace);
buff = null;
}
finally
{
if (dataSet != null)
dataSet.Dispose();
if (adapter != null)
adapter.Dispose();
} //stream.Close();
// there is an exception happened or update false
if (buff == null || iRtn == 0)
return false;
return true;
} #endregion

2.sql语句采用parameter

    string image = BlobToString(DBConnection.m_DataBaseConn, "imagetable", "ImageData", "ImageID", readerIl[0].ToString());
if (image == null) { readerIl2.Close(); continue; }
byte[] bytes = strhelper.str2arr(image);
cmmandIr.CommandText = "update imagetable set imagedata = ? where imageid = '" + readerIl[0].ToString() + "'";
commandIr.Parameters.Add("@a", bytes);
commandIr.ExecuteNonQuery();

c# mysql blob数据类型的更多相关文章

  1. MySQL的数据类型(转)

    MySQL的数据类型 1.整数 TINYINT: 8 bit 存储空间 SMALLINT: 16 bit 存储空间 MEDIUMINT: 24 bit 存储空间 INT: 32 bit 存储空间 BI ...

  2. mysql的数据类型和字段属性

    本文内容: 数据类型 数值类型 整数型 浮点型 定点型 日期时间类型 字符串类型 补充: 显示宽度与zerofll 记录长度 字段属性 空\不为空值:NULL.NOT NULL 主键:primary ...

  3. { MySQL基础数据类型}一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型

    MySQL基础数据类型 阅读目录 一 介绍 二 数值类型 三 日期类型 四 字符串类型 五 枚举类型与集合类型 一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己 ...

  4. mysql的数据类型和字符集

    MySQL的数据类型 MySQL数据库支持的数据类型主要有以下几种: 整型 浮点型 字符 BLOB型 枚举和集合类型 JSON类型(MySQL5.7新增加的支持) 整型 整数类型是数据库中最基本的数据 ...

  5. mysql 常见数据类型

    ---恢复内容开始--- MySQL常见的数据类型 一.数据类型是什么? 数据类型是指列.存储过程参数.表达式和局部变量的数据特征,它决定了数据的存储格式,代表了不同的信息类型. 有一些数据是要存储为 ...

  6. MYSQL中数据类型介绍

    一.MySQL的数据类型 主要包括以下五大类: 主要包括以下五大类: 整数类型:bit.  int . bit int . small int . tiny int . medium int .boo ...

  7. MySQL基础数据类型

    一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 详细参考: http://www.runoob.com/mysql/mysql-data ...

  8. MYSQL数据库数据类型

    07.14自我总结 MYSQL数据库数据类型 一.整数类型和浮点数典型 1.有符号/没符号 对于整数和负整数来说,默认情况下是有符号范围的 默认是有符号 有符号和没符号其实就是有没有包括负数,有符号是 ...

  9. MySQL学习——数据类型

    MySQL学习——数据类型 摘要:本文主要学习了MySQL数据库的数据类型. 整数类型 MySQL主要提供的整数类型有tinyint.smallint.mediumint.int.bigint,其属性 ...

随机推荐

  1. SpringBoot非官方教程 | 第十八篇: 定时任务(Scheduling Tasks)

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot18-scheduling/ 本文出自方志朋的博客 ...

  2. sql*plus

    [sql*plus创建txt文档编辑sql语句] (1)创建一个txt,命名doc SQL> ed  doc;          /*ed   文件名*/ (2)在doc.txt文件编辑sql语 ...

  3. 解决model属性与系统重名

    .h .m + (NSDictionary *)replacedKeyFromPropertyName { return @{ @"detailId" : @"id&qu ...

  4. 解决ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)【亲测有效】

    文件转自:https://blog.csdn.net/hua1011161696/article/details/80666025 问题:(MySQL 5.6社区版windows版) 忘记密码或其他一 ...

  5. Spring Boot2.4双数据源的配置

    相较于单数据源,双数据源配置有时候在数据分库的时候可能更加有利 但是在参考诸多博客以及书籍(汪云飞的实战书)的时候,发现对于spring boot1.X是完全没问题的,一旦切换到spring boot ...

  6. 发送post请求几种常见content-type类型

    application/x-www-form-urlencoded 这应该是最常见的 POST 提交数据的方式了.浏览器的原生 form 表单,如果不设置 enctype 属性,那么最终就会以 app ...

  7. 数据库中pymysql模块的使用

    pymysql 模块 使用步骤: 核心类Connect链接用和Cursor读写用 1. 与数据库服务器建立链接 2. 获取游标对象(用于发送和接收数据) 3. 用游标执行sql语句 4. 使用fetc ...

  8. Leecode刷题之旅-C语言/python-100相同的树

    /* * @lc app=leetcode.cn id=100 lang=c * * [100] 相同的树 * * https://leetcode-cn.com/problems/same-tree ...

  9. Linux 之vi与vim

    vi 三种模式: 『一般模式』: 光标 『编辑模式』:i,o,a,r 『指令列命令模式』「:/ ?」 例子: 1. 请在/tmp 这个目录下建立一个名为vitest 的目录: 2. 将/etc/man ...

  10. LeetCode:19. Remove Nth Node From End of List(Medium)

    1. 原题链接 https://leetcode.com/problems/remove-nth-node-from-end-of-list/description/ 2. 题目要求 给出一个链表,请 ...