博文
在VB.NET中如何读取和存储ACESSS数据库中的图片(2008-02-20 21:15:00)
摘要:'首先将数据读入dataset中
Dim ImgByt() As Byte
Dim ImgMS As IO.MemoryStream
ImgByt = CType(dataset.Tables("表名").Rows(0).Item("图片字段名"), Byte())
ImgMS = New IO.MemoryStream(ImgByt)
PictureBox1.image = Drawing.Image.FromStream(ImgMS)
Try
Dim strInsert As String
&nbs......
将资料以二进制方式存入MsSql数据库(2008-02-20 21:13:00)
摘要:
将资料以二进制方式存入MsSql数据库
[日期:2007-11-23]
来源:asp.net魔法学院 作者:佚名
[字体:大 中 小]
这个范例示范了如何将档案存入资料库中的 Image 栏位及如何由 Image 栏位取出该档案。
假设资料表 Tb_File 有 ID,ExcelFile 两个栏位,ID 栏位型态为Integer,ExcelFile 栏位型态为 Image,先加入一笔记录,ID=1,ExcelFile=Null,范例中将Excel档案利用Update写入ID=1的记录中及由此记录读取 Image栏位内容并储存成档案。
’’’ <summary>
’’’ 读取档案内容写入Buffer中。
’’’ </summary>
Function FileToBuffer(ByVal FileName As String, ByRef Buffer() As Byte) As Boolean
Dim oFileStream As System.IO.FileStream
If Not System.IO.File.Exists(FileName) Then
&n......
ASP.NET2.0中将文件上传到数据库(2008-02-20 21:11:00)
摘要:此问题经常被人问,本文列出将文字和图片上传到数据库的方法。包括Access数据库和SQL Server数据库。
Access数据库代码
protected void Button1_Click( object sender, EventArgs e )
{
System.IO.Stream fileDataStream = FileUpload1.PostedFile.InputStream;
if (fileDataStream.Length < 1)
{
Msg.Text = "请选择文件。";
return;
}
//得到文件大小
int fileLength = FileUpload1.PostedFile.ContentLength;
//创建数组
byte[] fileData = new byte[fileLength];
//把文件流填充到数组
fileDataStream.Read(fileData, 0, fileLength);
//得到文件类型
string fileType = FileUpload1.PostedFile.ContentType;
//构建数据库连接,SQL语句,创建参数
string strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Image2Access.mdb");
OleDbConnection myConnection = new OleDbConnection(strCnn);
OleDbCommand command = new OleDbCommand("INSERT INTO Person (PersonName,PersonEmail,PersonSex,PersonImageType,PersonImage)" +
"VALUES (@PersonName,@PersonEmail,@PersonSex,@PersonImageType,@Perso......
我的第一个Access数据库程序(全面、源码)(2007-02-10 08:39:00)
摘要:Introduction
No, no, this isn't going to be some "Use-the-Data-Form-Wizard" nonsense. Neither is this going to be a real-world program. But before you grumble, curse, and look elsewhere, you should know that the code here will help you to write that real-world program you're probably after. Of course, you will have to make the necessary changes, and that's why I start with something very general and simple.
I don't want to bother you with things such as writing the Access database or starting your design totally from scratch. It's not that I'm lazy; it's more in consideration of those who have such an awfully slow dial-up connection. Such a connection can be a spoilsport when it takes ages to load the page. Since this tutorial is going to be a bit - but just a bit - large, I'm happy when I can cut down on things. Believe me, you'll be happy about that, too - unless you have one of those speedy connections.
Before you start
Before you get going, download the Starter Solution. This S......
GUI+实现垂直字符串在Label控件上(2007-02-10 08:33:00)
摘要:Vertical Text: Top to Bottom
Problem:
You want to want to write a text string on a label vertically, top to bottom (rotated 90 degrees clockwise)
Solution
Draw the string on the label using the Graphics DrawString method. Use the FormatFlags Property of the System.Drawing.StringFormat Class, selecting DirectionVertical from the StringFormatFlags Enumeration.
Code
If that sounds technical, it’s only because there are several steps involved, but it isn’t really as complicated as it might seem. Let’s start with the code, then we can break it down into understandable steps.
Place a label named Label1 on a form. Put this Imports statement at the top of the form:
Imports System.Drawing.Text
And this code in the Label’s Paint event:
Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint......
GUI+画图1(2007-02-10 08:30:00)
摘要:Let’s Not Reinvent the Wheel
In many situations the familiar pie chart is as good a way as any of presenting data in pictorial form. The Graphics Class in .Net offers us an easy way to create this style of chart in order to display facts and figures to the world.
The above chart can be created with very few lines of code.
However, it is obviously of very limited use on its own. The picture is colourful, but we need to know what the segments represent.
Let’s look at a basic but quite useful way of doing this – using a chart key:
With a key like the one shown above, it is very easy for the user to identify which part of the pie chart represents which of the companies. To make the data even more useful, each company’s individual total is also shown in the key.
As you will see, the Graphics Class in the......
GUI+画图2(2007-02-10 08:27:00)
摘要:Picture This
In Part 1 we created a Pie Chart by drawing directly on to the surface of the form using the form’s Graphics object. In this article, we are going to create a Bar Chart, again based on some notional sample data - sales figures from six European countries. However, this time we will draw the Bar Chart inside a PictureBox control.
In general, there is little difference between the two approaches – drawing on the form itself or drawing inside the picturebox.
In this project, we will draw the chart once the user has clicked a Button. As in Part 1, the display will be redrawn whenever it has been obscured or changed (this is known as "persisting" the drawing).
In the Pie Chart example we used the form’s OnPaint method to recreate the chart every time a redraw was required. This approach is absolutely fine in most situations . However, in orde......
GUI+画图3(2007-02-10 08:24:00)
摘要:Setting Out The Form
Skeleton Layout
Because these articles are aimed at showing you how to use the Graphics Classes, I will skim over most of the non-graphics stuff wherever I can. So, to help shortcut the process of creating the Windows Form and its controls, I have included a project containing a skeleton form (i.e. it contains the controls, but none of the graphics code). You will find it in the folder named "Skeleton" in the attached zip file.
The form and its controls looks like this:
Of course, if you prefer to build the form yourself, go ahead. I will let you know the names used and other details for the controls where these are significant to the code as we come to them.
Let's get Coding
Insert these statements at the top of the form:
Option Strict On
Imports System.Drawing.Drawing2D
Imports System.Collections
As in the previous articles, a Structure is used t......
GUI+图像处理4(2007-02-10 08:20:00)
摘要:Setting Up
Data Source
First, let’s generate some data to display via the chart. We will create it at design time to allow us to get on with the core Graphics Class parts of the project. If you prefer to have the data input by the user at run time then you can adapt the techniques covered in Part 3.
Create Data
Shown below is what has become our standard code to create initial variables and to generate and store some data. I won’t trundle through the details as they are fully covered in earlier articles:
Option Strict On
Imports System.Drawing.Drawing2D
Imports System.Collections
Structure GraphData
Dim Country As String
Dim Sales As Integer
Dim BarColor As Color
Sub New(ByVal country A......
使用GUI+画折线图(2007-02-10 08:15:00)
摘要:Introduction
Outline
As in the previous articles, the chart will be displayed in a PictureBox control. Although it would be easy - easier in some ways - to simply plaster the chart onto the surface of the form itself, I think it is more realistic to house it inside some kind of container control because a chart is most often just one part of a range of information displayed to the user. It also lends itself more easily to the situation where you want to take user input on screen and to use that data directly to draw or redraw the chart.
For convenience, we will create some sample data at the start of the project. In a real world scenario, you will probably gather this data from a data source of some kind, either one that has been previously saved to file or directly from the user on screen. If you want to adjust the code in this article to take in data at runtime, you will find an ......