当前位置:网站首页>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 .
边栏推荐
- 漫画:一道数学题引发的血案
- SQL Server(2)
- CMake教程Step5(添加系统自检)
- MySQL queries the latest qualified data rows
- Cmake tutorial step6 (add custom commands and generate files)
- 【7.7直播预告】《SaaS云原生应用典型架构》大咖讲师教你轻松构建云原生SaaS化应用,难题一一击破,更有华为周边好礼等你领!
- About JSON parsing function JSON in MySQL_ EXTRACT
- Embedded -arm (bare board development) -2
- Flow characteristics of kitchen knife, ant sword, ice scorpion and Godzilla
- flask解决CORS ERR 问题
猜你喜欢
随机推荐
Force deduction solution summary 729- my schedule I
Design of electronic clock based on 51 single chip microcomputer
CVPR 2022 best student paper: single image estimation object pose estimation in 3D space
Embedded UC (UNIX System Advanced Programming) -3
Embedded-c Language-3
Function sub file writing
Embedded UC (UNIX System Advanced Programming) -2
力扣解法汇总729-我的日程安排表 I
Embedded -arm (bare board development) -2
Use JDBC technology and MySQL database management system to realize the function of course management, including adding, modifying, querying and deleting course information.
Understand the usage of functions and methods in go language
[Web attack and Defense] WAF detection technology map
Example tutorial of SQL deduplication
蚂蚁金服的暴富还未开始,Zoom的神话却仍在继续!
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
ICML 2022 | meta proposes a robust multi-objective Bayesian optimization method to effectively deal with input noise
基于Redis实现延时队列的优化方案小结
33:第三章:开发通行证服务:16:使用Redis缓存用户信息;(以减轻数据库的压力)
goto Statement
stirring! 2022 open atom global open source summit registration is hot!




