前一段时间写了个编写XML的小东西,当时没怎么整理,也没涉及到图片的处理。
今天这个是可以存储和管理的例子,增加了图片管理的这一功能
测试环境:Windows XP Pro +VS.NET 2003+ MS SQL 2000 (均为英文版)
PS:学习中,望不吝赐教!
偶就简单的介绍下代码
1,包含的命名空间
4,创建数据表的代码
今天这个是可以存储和管理的例子,增加了图片管理的这一功能
测试环境:Windows XP Pro +VS.NET 2003+ MS SQL 2000 (均为英文版)
PS:学习中,望不吝赐教!
偶就简单的介绍下代码
1,包含的命名空间
CODE:
Option Strict On
Imports System.IO
Imports System.Data.SqlClient
Imports System.Text
2,一些共有变量的声明:Imports System.IO
Imports System.Data.SqlClient
Imports System.Text
CODE:
Protected Const SQL_CONNECTION_STRING As String = _
"Server=localhost;" & _
"DataBase=Northwind;" & _
"Integrated Security=SSPI"
Protected Const CONNECTION_ERROR_MSG As String = _
"You must have SQL with the Northwind database installed. "
Protected da As SqlDataAdapter
Protected cbd As SqlCommandBuilder
Protected dsPictures As DataSet
Protected didPreviouslyConnect As Boolean = False
Protected connectionString As String = SQL_CONNECTION_STRING
3,略去Windows Form Designer Generate Code这个部分,可参见偶贴图"Server=localhost;" & _
"DataBase=Northwind;" & _
"Integrated Security=SSPI"
Protected Const CONNECTION_ERROR_MSG As String = _
"You must have SQL with the Northwind database installed. "
Protected da As SqlDataAdapter
Protected cbd As SqlCommandBuilder
Protected dsPictures As DataSet
Protected didPreviouslyConnect As Boolean = False
Protected connectionString As String = SQL_CONNECTION_STRING
4,创建数据表的代码
CODE:
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim strSQL As String = _
"IF EXISTS (" & _
"SELECT * " & _
"FROM northwind.dbo.sysobjects " & _
"WHERE NAME = 'Picture' " & _
"AND TYPE = 'u')" & vbCrLf & _
"BEGIN" & vbCrLf & _
"DROP TABLE northwind.dbo.picture" & vbCrLf & _
"END" & vbCrLf & _
"CREATE TABLE Picture (" & _
"PictureID Int IDENTITY(1,1) NOT NULL," & _
"[FileName] Varchar(255) NOT NULL," & _
"Picture Image NOT NULL," & _
"Name nvarchar(20) NOT NULL," & _
"UID Varchar(20) NOT NULL," & _
"UG nvarchar(10) NOT NULL," & _
"Gender nvarchar(10) NOT NULL," & _
"Score nvarchar(50) NOT NULL," & _
"SelfIntr Varchar(255) NOT NULL," & _
"CONSTRAINT [PK_Picture] PRIMARY KEY CLUSTERED" & _
"(PictureID))"
Dim frmMessage As New status
If Not didPreviouslyConnect Then
frmMessage.Show("Connecting to SQL Server")
End
Dim strSQL As String = _
"IF EXISTS (" & _
"SELECT * " & _
"FROM northwind.dbo.sysobjects " & _
"WHERE NAME = 'Picture' " & _
"AND TYPE = 'u')" & vbCrLf & _
"BEGIN" & vbCrLf & _
"DROP TABLE northwind.dbo.picture" & vbCrLf & _
"END" & vbCrLf & _
"CREATE TABLE Picture (" & _
"PictureID Int IDENTITY(1,1) NOT NULL," & _
"[FileName] Varchar(255) NOT NULL," & _
"Picture Image NOT NULL," & _
"Name nvarchar(20) NOT NULL," & _
"UID Varchar(20) NOT NULL," & _
"UG nvarchar(10) NOT NULL," & _
"Gender nvarchar(10) NOT NULL," & _
"Score nvarchar(50) NOT NULL," & _
"SelfIntr Varchar(255) NOT NULL," & _
"CONSTRAINT [PK_Picture] PRIMARY KEY CLUSTERED" & _
"(PictureID))"
Dim frmMessage As New status
If Not didPreviouslyConnect Then
frmMessage.Show("Connecting to SQL Server")
End