我爱Aspx >> C#.Net >> 通过ADO.NET存取文件_ADO.NET应用
有时我们需要把一些大的数据对象如图片、可执行文件、视频和文档等数据存入数据库。在MS SQL Server中,这要用到Image数据类型,可以保存多达2G的数据。以下给出一个通过ADO.NET和MS SQL Server实现的小小的例子。
先创建一个测试数据表。
在查询分析器中输入并执行以下语句:
Create table [imgtable](
[imgid] [int] IDENTITY(1,1) NOT NULL,
[imgname] [varchar](100) COLLATE Chinese_PRC_CI_AS NULL,
[imgData] [image] NULL,
PRIMARY KEY CLUSTERED
(
[imgid]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
这要在你所选的数据库中就多了一个名叫imgtable的表。
VS中的代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace ADO_Demo
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class ADO_Demo : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.Button button3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public ADO_Demo()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Ҷƪл˵?
下一代ADO.NET---ADO.NET Entity..[04-28]
ADO.NET2.0跟ADO.NET3.0的一些新..[04-28]
ADO.NET 2.0:如何排除错误信息「..[04-28]
ADO.NET中的sql连接_ADO.NET应用[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
ado.net数据库连接_ADO.NET应用[04-28]
数据库开发个人总结(ADO.NET小结..[04-28]
下一代ADO.NET---ADO.NET Entity..[04-28]
ADO.NET2.0跟ADO.NET3.0的一些新..[04-28]
ADO.NET 2.0:如何排除错误信息「..[04-28]
ADO.NET中的sql连接_ADO.NET应用[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
使用ADO.NET2.0提升数据交互性能..[04-28]
ado.net数据库连接_ADO.NET应用[04-28]
数据库开发个人总结(ADO.NET小结..[04-28]