当前位置:网站首页>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 .
边栏推荐
- IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
- Debug kernel code through proc interface
- 中国银河证券开户安全吗 开户后多久能买股票
- 7.Scala类
- ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
- mongodb(快速上手)(一)
- Winedt common shortcut key modify shortcut key latex compile button
- stirring! 2022 open atom global open source summit registration is hot!
- MySQL之知识点(七)
- Cloud security daily 220705: the red hat PHP interpreter has found a vulnerability of executing arbitrary code, which needs to be upgraded as soon as possible
猜你喜欢
MySQL之知识点(七)
How to write a full score project document | acquisition technology
一个满分的项目文档是如何书写的|得物技术
IDC报告:腾讯云数据库稳居关系型数据库市场TOP 2!
IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
Alpha conversion from gamma space to linner space under URP (II) -- multi alpha map superposition
Example tutorial of SQL deduplication
Three traversal methods of binary tree
mysql中取出json字段的小技巧
随机推荐
C#实现水晶报表绑定数据并实现打印3-二维码条形码
Read the history of it development in one breath
The first lesson of EasyX learning
基于Redis实现延时队列的优化方案小结
漫画:一道数学题引发的血案
How MySQL uses JSON_ Extract() takes JSON value
Cartoon: how to multiply large integers? (next)
IDEA 项目启动报错 Shorten the command line via JAR manifest or via a classpath file and rerun.
北京内推 | 微软亚洲研究院机器学习组招聘NLP/语音合成等方向全职研究员
Judge whether a string is a full letter sentence
Error in compiling libssh2. OpenSSL cannot be found
Embedded UC (UNIX System Advanced Programming) -3
About JSON parsing function JSON in MySQL_ EXTRACT
Force deduction solution summary 729- my schedule I
CMake教程Step6(添加自定义命令和生成文件)
Embedded UC (UNIX System Advanced Programming) -1
Database design in multi tenant mode
Thoughtworks 全球CTO:按需求构建架构,过度工程只会“劳民伤财”
Using C language to realize palindrome number
Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?