DataBaseTableDesing:

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

圖片二進制數據庫的存取和讀取...

系統 1827 0

圖片二進制數據庫的存取和讀取 <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

DataBase Table Desing:

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 82.5pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Cwei_zhu%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.png"></imagedata></shape>

圖片二進制數據庫的存取和讀取...

-Function:

1. 導入圖像文件,以二進制形式存入數據庫表。

2. 從數據庫表讀取二進制信息,返原顯示在頁面的 datagrid

<shape id="_x0000_i1026" style="WIDTH: 411pt; HEIGHT: 405pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Cwei_zhu%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image003.png"></imagedata></shape>

圖片二進制數據庫的存取和讀取...

--- Web.Config ---

<? xml version = " 1.0 " encoding = " utf-8 " ?>

< configuration >

<!-- application specific settings -->

< appSettings >

< add key = " uid " value = " sa " />

< add key = " pwd " value = "" />

< add key = " server " value = " 10.33.220.87 " />

< add key = " database " value = " test " />

</ appSettings >

< system.web >

--- Code Section WebForm2.aspx ---

<% @ Page Language ="vb" AutoEventWireup ="false" Codebehind ="WebForm2.aspx.vb" Inherits ="EmployeeInfo.WebForm2" %>

< HTML >

< HEAD >

< title > WebForm2 </ title >

< meta content ="Microsoft Visual Studio .NET 7.1" name ="GENERATOR">

< meta content ="Visual Basic .NET 7.1" name ="CODE_LANGUAGE">

< meta content ="JavaScript" name ="vs_defaultClientScript">

< meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema">

</ HEAD >

< body MS_POSITIONING ="GridLayout">

< form id ="Form1" method ="post" runat ="server">

< INPUT id ="File1" style ="Z-INDEX: 101; LEFT: 128px; POSITION: absolute; TOP: 72px" type ="file"

runat ="server">

< asp : datagrid id ="DataGrid1" style ="Z-INDEX: 106; LEFT: 24px; POSITION: absolute; TOP: 208px"

runat ="server" Width ="464px" Height ="136px" AutoGenerateColumns ="False">

< Columns >

< asp : BoundColumn DataField ="BadgeNO" HeaderText ="Badge No"></ asp : BoundColumn >

< asp : TemplateColumn HeaderText ="Photo">

< ItemTemplate >

< asp : Image ID ="Photo" Runat ="server"></ asp : Image >

</ ItemTemplate >

< HeaderStyle Width ="160px" />

</ asp : TemplateColumn >

</ Columns >

</ asp : datagrid >< asp : label id ="Label1" style ="Z-INDEX: 102; LEFT: 24px; POSITION: absolute; TOP: 184px" runat ="server"

Width ="152px" Height ="16px" BackColor ="Gray" Font-Bold ="True"> Employee Report </ asp : label >< asp : button id ="Button_Insert" style ="Z-INDEX: 103; LEFT: 384px; POSITION: absolute; TOP: 72px"

runat ="server" Text ="Insert" Width ="56px"></ asp : button >

< asp : TextBox id ="Tbx_BadgeNo" style ="Z-INDEX: 104; LEFT: 128px; POSITION: absolute; TOP: 40px"

runat ="server"></ asp : TextBox >

< asp : Button id ="Button_Report" style ="Z-INDEX: 105; LEFT: 384px; POSITION: absolute; TOP: 112px"

runat ="server" Text ="Report"></ asp : Button ></ form >

</ body >

</ HTML >

--- Code Section WebFor2.vb ---

Imports System

Imports System.Drawing

Imports System.IO

Imports System.Data.SqlClient

Public Class WebForm2

Inherits System.Web.UI.Page

# Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile

Protected WithEvents Tbx_BadgeNo As System.Web.UI.WebControls.TextBox

Protected WithEvents Button_Insert As System.Web.UI.WebControls.Button

Protected WithEvents Button_Report As System.Web.UI.WebControls.Button

Protected WithEvents Label1 As System.Web.UI.WebControls.Label

Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

# End Region

Private connString As String

Private Sub InitalDB()

Dim uid = ConfigurationSettings.AppSettings( "uid" )

Dim pwd = ConfigurationSettings.AppSettings( "pwd" )

Dim server = ConfigurationSettings.AppSettings( "server" )

Dim database = ConfigurationSettings.AppSettings( "database" )

connString = "server=" & server & ";uid=" & uid & ";pwd=" & pwd & ";database=" & database

End Sub

Private Sub Page_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load

'Put user code to initialize the page here

InitalDB()

End Sub

Private Sub Button_Report_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Report.Click

ShowPhoto()

End Sub

Private Sub ShowPhoto()

Dim dt As New DataTable

Dim myConn As SqlConnection = New SqlConnection(connString)

Dim sql As String = " SELECT * FROM tb_1 "

myConn.Open()

Dim adp As New SqlDataAdapter(sql, myConn)

adp.Fill(dt)

For lint_index As Integer = 0 To dt.Rows.Count - 1

Dim photo() As Byte = CType (dt.Rows(lint_index).Item( "Photo" ), Byte ())

' Me.Response.BinaryWrite(photo)

Dim lstg_badgeno As String

lstg_badgeno = dt.Rows(lint_index).Item( "BadgeNo" )

Dim strPath As String = "~/photo/" + lstg_badgeno + ".JPG"

Dim strPhotoPath As String = Server.MapPath(strPath)

Dim bw As BinaryWriter = New BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate))

bw.Write(photo)

bw.Close()

Next

myConn.Close()

Me .DataGrid1.DataSource = dt

Me .DataGrid1.DataBind()

UpdatePhoto()

End Sub

Private Sub Button_Insert_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Insert.Click

Try

Dim strPath As String = Me .File1.PostedFile.FileName

Dim BadgeNo As String = Me .Tbx_BadgeNo.Text

'Dim strPhotoPath As String = Server.MapPath(strPath)

' 讀取圖片

' Dim fs As FileStream = New System.IO.FileStream(strPhotoPath, FileMode.Open, FileAccess.Read)

Dim fs As FileStream = New System.IO.FileStream(strPath, FileMode.Open, FileAccess.Read)

Dim br As BinaryReader = New BinaryReader(fs)

Dim photo() As Byte = br.ReadBytes( CType (fs.Length, Integer ))

br.Close()

fs.Close()

Dim myConn As SqlConnection = New SqlConnection(connString)

Dim strComm As String = " INSERT INTO tb_1(BadgeNo,Photo) "

strComm = (strComm + ( " VALUES('" + BadgeNo + "', @photoBinary )" ))

Dim myComm As SqlCommand = New SqlCommand(strComm, myConn)

myComm.Parameters.Add( "@photoBinary" , SqlDbType.Binary, photo.Length)

myComm.Parameters( "@photoBinary" ).Value = photo

myConn.Open()

myComm.ExecuteNonQuery()

myConn.Close()

Catch ex As Exception

Response.Write(ex.ToString)

End Try

ShowPhoto()

End Sub

'---Bind Photo---

Private Sub UpdatePhoto()

For Each lobj_dgi As DataGridItem In Me .DataGrid1.Items

Dim tmp_Image As System.Web.UI.WebControls.Image = CType (lobj_dgi.Cells(1).FindControl( "Photo" ), System.Web.UI.WebControls.Image)

Dim lstg_badgeno As String = lobj_dgi.Cells(0).Text

tmp_Image.ImageUrl = "~/photo/" + lstg_badgeno + ".JPG"

Next

End Sub

End Class

圖片二進制數據庫的存取和讀取...


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: www.国产一区二区三区 | 在线视频综合网 | 麻豆a| 亚洲短视频在线观看 | 免费国产之a视频 | 久久久成人啪啪免费网站 | 亚洲精品一区二区深夜福利 | 番茄视频在线观看黄版本免费 | 羞羞视频网站 | 伊人亚洲 | 亚洲综合久久久久久中文字幕 | 免费看色 | 国产视频在线播放 | 国产成人精品亚洲日本在线 | 国产三级久久 | 国语精品91自产拍在线观看二区 | 香焦视频在线观看黄 | 男人手机天堂 | 91色多多| 久久国产精品99久久久久久牛牛 | 国产极品白嫩美女在线观看看 | 伊人精品成人久久综合欧美 | 自拍视频国产 | 香蕉黄色网 | 在线亚洲 欧美 日本专区 | 国产高清美女一级a毛片久久 | 91九色视频在线观看 | 亚洲视频天天射 | 国产精品日韩欧美一区二区 | 99热国产这里只有精品 | 国产操女人 | 国产一级淫片a视频免费观看 | 国产亚洲精品福利片 | 久久99精品久久久久久秒播放器 | 欧美亚洲综合一区 | 国产一级持黄大片99久久 | 欧美成人免费全部观看天天性色 | 99热久久久久久久免费观看 | 中文字幕曰韩一区二区不卡 | 久久久久久久99精品免费 | 免费亚洲视频在线观看 |