• byte数组存储到mysql


     public int AddVeinMessage(byte[] data)//插入数据库
            {
                using (BCSSqlConnection = new MySqlConnection(strConn))
                {
                    try
                    {
                        dbHelper = new DBHelper(BCSSqlConnection);
                        StringBuilder sbSql = new StringBuilder();
    
                        sbSql.Append("insert into table1(");
                        sbSql.Append("data)");
                        sbSql.Append(" values (");
                        sbSql.Append(" ?data)");
    
                        string strInsertSql = sbSql.ToString();
                        MySqlCommand cmd = dbHelper.GetSqlStringCommond(strInsertSql);
    
                        dbHelper.AddInParameter(cmd, "?data", MySqlDbType.VarBinary, FINGERDATA);
    
                        return dbHelper.ExecuteNonQuery(cmd);
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show("添加失败了" + ex.Message);
                        return 0;                           //表示数据库异常
                    }
                    finally
                    {
                        dbHelper.CloseSqlConnection();       //关闭数据库
                    }
                }
            }

    从数据库中取出

    public DataTable SelectVeinMessage()
            {
                using (BCSSqlConnection = new MySqlConnection(strConn))
                {
                    try
                    {
                        StringBuilder sbSql = new StringBuilder();
                        sbSql.Append("select data from table");
                        //设置MYSQL查询语句用于查询符合查询条件的记录
                        string strSql = sbSql.ToString();
                        dbHelper = new DBHelper(BCSSqlConnection);
                        //调用DBHelper类中的GetSqlStringCommond()方法将返回的MySqlCommand对象赋给cmd
                        MySqlCommand cmd = dbHelper.GetSqlStringCommond(strSql);
                        // dbHelper.AddInParameter(cmd, "?FINGERDATA", MySqlDbType.VarChar, FINGERDATA);
                        //调用DBHelper类的ExecuteDataSet()方法
                        DataTable dt = dbHelper.ExecuteDataTable(cmd);
                        //返回DataTable对象dt
                        return dt;
                    }
                    catch (Exception e)
                    {
                        throw new Exception(e.Message);
                    }
                    finally
                    {
                        dbHelper.CloseSqlConnection();
                    }
                }
            }
     DataTable dt = mm.SelectVeinMessage1();
                byte[] TemplateBuff = new byte[512];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TemplateBuff = (byte[])dt.Rows[i]["data"];           
                } 
  • 相关阅读:
    Elasticsearchdump 数据导入/导出
    04.2 go-admin前后端打包为一个服务上线
    go-admin开发小技巧
    假设知道服务器IP,如何查询它绑定的域名?
    webstorm eslint 配置格式化的两种方式
    lodash中的深拷贝方法cloneDeep()
    go 操作elaticsearch
    gin返回json假数据
    gin 图片上传到本地或者oss
    世界地图
  • 原文地址:https://www.cnblogs.com/congcongdi/p/8966861.html
Copyright © 2020-2023  润新知