当前位置:网站首页>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 .
边栏推荐
- [7.7 live broadcast preview] the lecturer of "typical architecture of SaaS cloud native applications" teaches you to easily build cloud native SaaS applications. Once the problem is solved, Huawei's s
- Cartoon: how to multiply large integers? (I) revised version
- Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?
- 普通程序员看代码,顶级程序员看趋势
- CMake教程Step1(基本起点)
- winedt常用快捷键 修改快捷键latex编译按钮
- CMake教程Step3(添加库的使用要求)
- WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands
- Read the history of it development in one breath
- How to write a full score project document | acquisition technology
猜你喜欢
Embedded -arm (bare board development) -1
Using C language to realize palindrome number
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
Kafaka技术第一课
深入理解Redis内存淘汰策略
机器学习01:绪论
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions
腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权
Use of ThinkPHP template
SQL删除重复数据的实例教程
随机推荐
Judge whether a number is a prime number (prime number)
URP下Alpha从Gamma空间到Linner空间转换(二)——多Alpha贴图叠加
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
张平安:加快云上数字创新,共建产业智慧生态
CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
2022年信息系统管理工程师考试大纲
Use of ThinkPHP template
Understand the usage of functions and methods in go language
winedt常用快捷键 修改快捷键latex编译按钮
统计php程序运行时间及设置PHP最长运行时间
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Complete solution instance of Oracle shrink table space
ClickHouse(03)ClickHouse怎么安装和部署
Cartoon: a bloody case caused by a math problem
漫画:有趣的【海盗】问题
Oracle缩表空间的完整解决实例
世界上最难的5种编程语言
基于51单片机的电子时钟设计
漫画:如何实现大整数相乘?(下)
Summary of optimization scheme for implementing delay queue based on redis