当前位置:网站首页>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 .
边栏推荐
- ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
- Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition
- About JSON parsing function JSON in MySQL_ EXTRACT
- Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
- The first lesson of EasyX learning
- winedt常用快捷键 修改快捷键latex编译按钮
- C # realizes crystal report binding data and printing 3-qr code barcode
- In depth understanding of redis memory obsolescence strategy
- BigDecimal除法的精度问题
- ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
猜你喜欢
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
What are the precautions for MySQL group by
Using C language to realize palindrome number
查看自己电脑连接过的WiFi密码
First day of learning C language
thinkphp模板的使用
Summary of optimization scheme for implementing delay queue based on redis
Example tutorial of SQL deduplication
WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands
MySQL之知识点(七)
随机推荐
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
Error in compiling libssh2. OpenSSL cannot be found
Kafaka technology lesson 1
排错-关于clion not found visual studio 的问题
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
漫画:如何实现大整数相乘?(整合版)
Machine learning 02: model evaluation
CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
ternary operator
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
MySql 查询符合条件的最新数据行
mysql如何使用JSON_EXTRACT()取json值
Cartoon: interesting pirate problem (full version)
ThoughtWorks global CTO: build the architecture according to needs, and excessive engineering will only "waste people and money"
Cartoon: how to multiply large integers? (next)
First day of learning C language
Complete solution instance of Oracle shrink table space
The first lesson of EasyX learning
Read the basic grammar of C language in one article
MySQL之知识点(六)