Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,037

HOME > บทความจากสมาชิก > ASP.NET BLOB Storing Binary Data



 
Clound SSD Virtual Server

ASP.NET BLOB Storing Binary Data

ASP.NET BLOB Storing Binary Data ตัวอย่าง asp.net กับการจัดเก็บข้อมูลในรูปแบบของ Binary Data ลงในฐานข้อมูลต่าง ๆ ผ่าน BLOB Data type กับฐานข้อมูล เช่น Microsoft Access , SQL Server , Oracle , MySQL

1. ASP.NET BLOB and Access Database

Code (VB.NET)
Imports System.Data
Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New OleDbConnection
            Dim strConnString, strSQL As String

			strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
			Server.MapPath("App_Data/mydatabase.mdb")&";Jet OLEDB:Database Password=;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (@sName,@sFilesName,@sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New OleDbCommand(strSQL, objConn)
            objCmd.Parameters.Add("@sName", OleDbType.VarChar).Value = Me.txtName.Text
            objCmd.Parameters.Add("@sFilesName", OleDbType.Binary).Value = imbByte
            objCmd.Parameters.Add("@sFilesType", OleDbType.VarChar).Value = strMIME
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class
อ่านเต็มรูปแบบได้ที่ : ASP.NET Access BLOB Binary Data and Parameterized Query








2. ASP.NET BLOB and MySQL Database

Code (VB.NET)
Imports System.Data
Imports MySql.Data.MySqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New MySqlConnection
            Dim strConnString, strSQL As String

            strConnString = "Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (?sName,?sFilesName,?sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New MySqlCommand(strSQL, objConn)
            objCmd.Parameters.Add("?sName", MySqlDbType.VarChar).Value = Me.txtName.Text
            objCmd.Parameters.Add("?sFilesName", MySqlDbType.Binary).Value = imbByte
            objCmd.Parameters.Add("?sFilesType", MySqlDbType.VarChar).Value = strMIME
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class
อ่านเต็มรูปแบบได้ที่ : ASP.NET MySQL BLOB Binary Data and Parameterized Query




3. ASP.NET BLOB and SQL Server Database

Code (VB.NET)
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New SqlConnection
            Dim strConnString, strSQL As String

            strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (@sName,@sFilesName,@sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New SqlCommand(strSQL, objConn)
            objCmd.Parameters.Add("@sName", SqlDbType.VarChar).Value = Me.txtName.Text
            objCmd.Parameters.Add("@sFilesName", SqlDbType.Binary).Value = imbByte
            objCmd.Parameters.Add("@sFilesType", SqlDbType.VarChar).Value = strMIME
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class
อ่านเต็มรูปแบบได้ที่ : ASP.NET SQL Server BLOB Binary Data and Parameterized Query








4. ASP.NET BLOB and Oracle Database

Code (VB.NET)
Imports System.Data
Imports System.Data.OracleClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New OracleConnection
            Dim strConnString, strSQL As String

			strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (:sName,:sFilesName,:sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New OracleCommand(strSQL, objConn)
            objCmd.Parameters.Add(":sName", OracleType.VarChar).Value = Me.txtName.Text
            objCmd.Parameters.Add(":sFilesName", OracleType.Blob).Value = imbByte
            objCmd.Parameters.Add(":sFilesType", OracleType.VarChar).Value = strMIME
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class
อ่านเต็มรูปแบบได้ที่ : ASP.NET Oracle BLOB Binary Data and Parameterized Query


   
Share
Bookmark.   

  By : TC Admin
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2011-06-02
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่