如何将文件存入数据库?

狼王_ 2010-09-30 10:55:51
我向实现将文件存入数据库中,我查的资料是将文件以二进制形式存入数据库,然后将文件从数据库中读出来重新构造这个文件。哪位做过这方面的程序啊?给个思路,有参考示例更好。。。多谢了。。
...全文
99 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinrongg 2010-09-30
  • 打赏
  • 举报
回复
接分








回复内容太短了!
兔子-顾问 2010-09-30
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace StructTest
{
public partial class Form1 : Form
{

string filename = @"d:\poi.st";

#region 结构体

//90

[StructLayout(LayoutKind.Sequential), Serializable]
public struct MY_STRUCT
{
public double x; //点的经度坐标
public double y; //点的纬度坐标
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
public string Name; //Name[40]; //名称
public long PointID; //点的ID号
public long TypeCode; //客户不使用该字段
}

#endregion

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MY_STRUCT[] arr = new MY_STRUCT[2];

MY_STRUCT np = new MY_STRUCT();
np.x = 114.123456;
np.y = 23.56789;
np.Name = "珠海市政府";
np.PointID = Convert.ToInt64(1234);
np.TypeCode = Convert.ToInt64(65);

arr[0] = np;

np = new MY_STRUCT();
np.x = 115.123456;
np.y = 24.56789;
np.Name = "珠海市政府2";
np.PointID = Convert.ToInt64(1235);
np.TypeCode = Convert.ToInt64(66);

arr[1] = np;

int structSize = Marshal.SizeOf(typeof(MY_STRUCT));
byte[] temp = new byte[structSize * arr.Length];
byte[] temp1 = Struct2Byte(arr[0]);
byte[] temp2 = Struct2Byte(arr[1]);

Array.Copy(temp1, 0, temp, 0, temp1.Length);
Array.Copy(temp2, 0, temp, structSize, temp2.Length);

WriteInfo(temp);
}


public void WriteInfo(byte[] bt)
{
if (File.Exists(filename))
{
File.Delete(filename);
return;
}

FileStream fs = new FileStream(filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(bt);
bw.Flush();

bw.Close();
fs.Close();

MessageBox.Show("保存成功!");
}

public byte[] ReadInfo(string file)
{
FileStream fs = new FileStream(file, FileMode.Open);
BinaryReader br = new BinaryReader(fs);

byte[] bt = br.ReadBytes(144);
br.Close();
fs.Close();

return bt;
}

private void button2_Click(object sender, EventArgs e)
{
byte[] bt = ReadInfo(filename);

int structSize = Marshal.SizeOf(typeof(MY_STRUCT));
int num = bt.Length / structSize;

for (int i = 0; i < num; i++)
{
byte[] temp = new byte[structSize];
Array.Copy(bt, i * structSize, temp, 0, structSize);

MY_STRUCT np = new MY_STRUCT();
np = Byte2Struct(temp);
}
}


private MY_STRUCT Byte2Struct(byte[] arr)
{
int structSize = Marshal.SizeOf(typeof(MY_STRUCT));
IntPtr ptemp = Marshal.AllocHGlobal(structSize);
Marshal.Copy(arr, 0, ptemp, structSize);
MY_STRUCT rs = (MY_STRUCT)Marshal.PtrToStructure(ptemp, typeof(MY_STRUCT));
Marshal.FreeHGlobal(ptemp);
return rs;
}

private byte[] Struct2Byte(MY_STRUCT s)
{
int structSize = Marshal.SizeOf(typeof(MY_STRUCT));
byte[] buffer = new byte[structSize];
//分配结构体大小的内存空间
IntPtr structPtr = Marshal.AllocHGlobal(structSize);
//将结构体拷到分配好的内存空间
Marshal.StructureToPtr(s, structPtr, false);
//从内存空间拷到byte数组
Marshal.Copy(structPtr, buffer, 0, structSize);
//释放内存空间
Marshal.FreeHGlobal(structPtr);
return buffer;
}

}
}


来自
http://www.cnblogs.com/baishahe/archive/2010/03/18/1688995.html
兔子-顾问 2010-09-30
  • 打赏
  • 举报
回复
http://www.111cn.net/net/33/2e5d36f4ce119fae64a2bb4b46e01247.htm
内容概要:SSD2828QN4是一款MIPI主桥接芯片,用于连接应用处理器与传统并行LCD接口及支持MIPI从属接口的LCD驱动器。该芯片支持最高每通道1Gbps的串行链路速度,最多可配置4个数据通道,显著减少了信号数量。它支持多种接口模式,包括RGB+SPI组合接口,适用于驱动智能或非智能显示面板,并能通过命令模式和视频模式传输数据。芯片内置时钟和复位模块、外部接口、协议控制单元(PCU)、包处理单元(PPU)、错误校正码/循环冗余校验(ECC/CRC)模块、长包和命令缓冲区、D-PHY控制器、模拟收发器以及内部锁相环(PLL),确保了高效的数据传输和系统稳定性。此外,文档详细描述了芯片的引脚分配、寄存器设置、操作模式、电源序列、时序特性等关键参数,为开发者提供了全面的技术指导。 适合人群:具备一定硬件设计基础,从事嵌入式系统开发、显示技术研究的研发人员。 使用场景及目标:①实现应用处理器与MIPI兼容显示屏之间的高速数据传输;②优化显示系统的功耗表现,减少电磁干扰(EMI);③通过灵活配置不同接口模式来适应各种显示设备的需求。 阅读建议:此文档面向具有一定电子工程背景的专业人士,建议读者结合实际项目需求深入理解各章节内容,特别是关于寄存器配置、时序要求等方面的具体说明。对于初次接触此类技术的开发者而言,建议先熟悉基本概念再逐步掌握高级功能的应用方法。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧