当前位置:网站首页>C # mixed graphics and text, written to the database in binary mode
C # mixed graphics and text, written to the database in binary mode
2022-07-05 17:29:00 【Game programming】
`

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Data.OleDb;using System.IO;namespace _07_ Binary save database { public partial class Form1 : Form { public Form1() { InitializeComponent(); } // Database connection string private static readonly string connStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DB.mdb"); MemoryStream StreamObject = null; // Write to the database Write button ************************************************************** private void button1_Click(object sender, EventArgs e) { Byte[] bt; //string str; // Use memory streams using (MemoryStream savefilestream = new MemoryStream()) { richTextBox1.SaveFile(savefilestream, RichTextBoxStreamType.RichText); bt = savefilestream.ToArray(); } //string sql = string.Format("insert into surface 1( Field 2)values(@ Field 2)"); string sql = string.Format("insert into surface 1( Field 2)values(@ Field 2)"); //string sql = "update Tab1 set [email protected] where id=1"; int a = CRdata(sql, "@ Field 2",bt); if (a > 0) { MessageBox.Show(" Write successfully "); } } // Read from database Read button ############################################################### private void button2_Click(object sender, EventArgs e) { //select Column 1, Column 2, Column 3 from Table name where Field 1 = '4'; string sql1 = string.Format("select Field 2 from surface 1 where ID=21"); // Read data from the database DataTable dt = DCdata(sql1); byte[] bWrite = (byte[])dt.Rows[0][0]; // Convert an array to stream System.IO.MemoryStream mstream = new System.IO.MemoryStream(bWrite, false); // take stream Fill in RichTextBox this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); } /// <summary> /// The method of writing text and pictures to the database . Binary array . /// </summary> /// <param name="sql"></param> /// <param name="paramName"></param> /// <param name="btArray"></param> /// <returns></returns> public static int CRdata(string sql,string paramName, byte[] btArray) { int returnResult = 0; using (OleDbConnection conn = new OleDbConnection(connStr)) { using (OleDbCommand comm = new OleDbCommand(sql, conn)) { conn.Open(); // This line determines whether the writing is successful . comm.Parameters.Add(paramName, OleDbType.Binary, btArray.GetLength(0)).Value = btArray; returnResult = comm.ExecuteNonQuery(); } conn.Close(); } return returnResult; } /// <summary> /// Read database method /// </summary> /// <param name="sql"></param> /// <param name="ReturnRowCounter"></param> /// <returns></returns> public static DataTable DCdata(string sql) { DataTable dt = new DataTable(); using (OleDbConnection conn = new OleDbConnection(connStr)) { using (OleDbDataAdapter ADP = new OleDbDataAdapter(sql, conn)) { //ReturnRowCounter = ADP.Fill(dt); ADP.Fill(dt); } } return dt; } }}author : Reading in rainy days
Game programming , A game development favorite ~
If the picture is not displayed for a long time , Please use Chrome Kernel browser .
边栏推荐
- mysql如何使用JSON_EXTRACT()取json值
- Read the history of it development in one breath
- Use of ThinkPHP template
- [binary tree] insufficient nodes on the root to leaf path
- 漫画:如何实现大整数相乘?(整合版)
- thinkphp模板的使用
- 独立开发,不失为程序员的一条出路
- Rider set the highlighted side of the selected word, remove the warning and suggest highlighting
- Cartoon: how to multiply large integers? (I) revised version
- 漫画:一道数学题引发的血案
猜你喜欢

Embedded-c Language-2

WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响

Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
深入理解Redis内存淘汰策略

激动人心!2022开放原子全球开源峰会报名火热开启!

基于51单片机的电子时钟设计

Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?

漏洞复现----48、Airflow dag中的命令注入(CVE-2020-11978)
In depth understanding of redis memory obsolescence strategy

Kafaka technology lesson 1
随机推荐
深入理解Redis内存淘汰策略
Cartoon: how to multiply large integers? (integrated version)
漫画:一道数学题引发的血案
Tita 绩效宝:如何为年中考核做准备?
Learn about MySQL transaction isolation level
ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
CMake教程Step6(添加自定义命令和生成文件)
Matery主题自定义(一)黑夜模式
Rider 设置选中单词侧边高亮,去除警告建议高亮
7. Scala class
Oracle缩表空间的完整解决实例
Force deduction solution summary 729- my schedule I
How MySQL uses JSON_ Extract() takes JSON value
Embedded-c Language-5
Cartoon: how to multiply large integers? (I) revised version
激动人心!2022开放原子全球开源峰会报名火热开启!
基于Redis实现延时队列的优化方案小结
关于mysql中的json解析函数JSON_EXTRACT