当前位置:网站首页>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 .
边栏推荐
- Debug kernel code through proc interface
- ICML 2022 | Meta提出魯棒的多目標貝葉斯優化方法,有效應對輸入噪聲
- Read the basic grammar of C language in one article
- Cartoon: interesting pirate problem (full version)
- 忽米沄析:工业互联网标识解析与企业信息系统的融合应用
- Learn about MySQL transaction isolation level
- BigDecimal除法的精度问题
- 编译libssh2报错找不到openssl
- SQL删除重复数据的实例教程
- thinkphp模板的使用
猜你喜欢
Using C language to realize palindrome number
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
7.Scala类
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
7. Scala class
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
33: Chapter 3: develop pass service: 16: use redis to cache user information; (to reduce the pressure on the database)
The second day of learning C language for Asian people
Embedded -arm (bare board development) -2
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
随机推荐
CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
深入理解Redis内存淘汰策略
漫画:如何实现大整数相乘?(整合版)
Rider set the highlighted side of the selected word, remove the warning and suggest highlighting
Q2 encryption market investment and financing report in 2022: gamefi becomes an investment keyword
Read the history of it development in one breath
Matery主题自定义(一)黑夜模式
力扣解法汇总1200-最小绝对差
张平安:加快云上数字创新,共建产业智慧生态
thinkphp模板的使用
Domain name resolution, reverse domain name resolution nbtstat
C#实现水晶报表绑定数据并实现打印3-二维码条形码
漫画:如何实现大整数相乘?(下)
mongodb(快速上手)(一)
Independent development is a way out for programmers
The five most difficult programming languages in the world
Example tutorial of SQL deduplication
Design of electronic clock based on 51 single chip microcomputer
WR | 西湖大学鞠峰组揭示微塑料污染对人工湿地菌群与脱氮功能的影响
Beijing internal promotion | the machine learning group of Microsoft Research Asia recruits full-time researchers in nlp/ speech synthesis and other directions