当前位置:网站首页>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 .
边栏推荐
- C#(Winform) 当前线程不在单线程单元中,因此无法实例化 ActiveX 控件
- Embedded-c Language-1
- 编译libssh2报错找不到openssl
- 排错-关于clion not found visual studio 的问题
- winedt常用快捷键 修改快捷键latex编译按钮
- 一个满分的项目文档是如何书写的|得物技术
- Use byte stream to read Chinese from file to console display
- Mysql5.6 parsing JSON strings (supporting complex nested formats)
- Machine learning 02: model evaluation
- flask解决CORS ERR 问题
猜你喜欢

Rider set the highlighted side of the selected word, remove the warning and suggest highlighting

基于51单片机的电子时钟设计

哈趣K1和哈趣H1哪个性价比更高?谁更值得入手?

Which is more cost-effective, haqu K1 or haqu H1? Who is more worth starting with?

Three traversal methods of binary tree

腾讯音乐上线新产品“曲易买”,提供音乐商用版权授权

First day of learning C language

Kafaka technology lesson 1

CVPR 2022 best student paper: single image estimation object pose estimation in 3D space

CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计
随机推荐
Is it safe for qiniu business school to open a stock account? Is it reliable?
Read the history of it development in one breath
Kafaka技术第一课
漫画:如何实现大整数相乘?(下)
High number | summary of calculation methods of volume of rotating body, double integral calculation of volume of rotating body
CMake教程Step1(基本起点)
Ordinary programmers look at the code, and top programmers look at the trend
C (WinForm) the current thread is not in a single threaded unit, so ActiveX controls cannot be instantiated
Force deduction solution summary 729- my schedule I
Embedded UC (UNIX System Advanced Programming) -3
SQL删除重复数据的实例教程
基于51单片机的电子时钟设计
这个17岁的黑客天才,破解了第一代iPhone!
Is it safe for China Galaxy Securities to open an account? How long can I buy stocks after opening an account
First day of learning C language
Embedded-c Language-4
The second day of learning C language for Asian people
WebApp开发-Google官方教程
How MySQL uses JSON_ Extract() takes JSON value
机器学习02:模型评估