|  | 
	                
  
    |  |  
    | 
        
        เก็บข้อมูลประเภทที่เป็น BLOB Binary  Data ลง mysql ยังไงครับ ช่วยที [VB.NET]     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | คือตอนนี้ผมทำเรื่องการเก็บลายนิ้วมืออยุ่ครับ ตอนนี้เรื่องการเก็บประวัติของเจ้าของลายนิ้วมือผมเก็บได้หมดแล้วครับ 
 แต่ .... ติดเพียงตรงที่ผมจะเก็บลายนิ้วมือที่เครื่องมันแปลงรูปภาพเป็น binary ยังไงครับ โดยฟิลด์ที่ใช้ในการเก็บผมกำหนดให้เป็น longblob
 
 ส่วนโค้ดก็ประมาณนี้ครับ
 Code (VB.NET)
 
 Private Sub ScanerCtrl1_OnEnrollSuccess(ByVal sender As System.Object, ByVal e As AxWACFPSCANER.__ScanerCtrl_OnEnrollSuccessEvent) Handles ScanerCtrl1.OnEnrollSuccess
        'e.quality is quality of fingerprint ( 1 - 10 ) 
        '1 is Worst
        '10 is Excellent
        LbMessage.Text = "Enroll success quality is " & e.quality.ToString() & " (" & CInt(e.quality) & ")"
        'Prepare byte array to storage fingerprint
        Dim EnrollData() As Byte
        'Get Enroll fingerprint from memory
        If ScanerCtrl1.GetEnrollData(EnrollData) = 0 Then
            Dim f As New frmAddName
            Dim retName As String
            retName = f.GetUserName()
            If retName = "" Then
                MsgBox("User name can't be null, please enroll again")
                Exit Sub
            End If
            On Error Resume Next
            conn = New MySqlConnection(connStr)
            conn.Open()
            sql = "Insert into user(uid, uname) values(NULL,'" & retName & "')"
            Dim cmd As MySqlCommand = New MySqlCommand(sql, conn)
            cmd.ExecuteNonQuery()
            conn.Close()
            conn.Dispose()
            Dim dates As String = Year(Today) & "/" & Now.ToString("mm/dd HH:MM:ss")
            sql = "Insert into fingerprint(fid, uname, ftemplate, fmodify) values(NULL, '" & retName & "', " & EnrollData & " , '" & dates & "')" 
'error ตรงนี้ด้วยนะครับมันแจ้งว่า Operator & is not defined for type 'String' and 1-dimensional array of byte
            cmd = New MySqlCommand(sql, conn)
            cmd.ExecuteNonQuery()
            conn.Close()
            conn.Dispose()
            '===========================================================================================
            FingerprintImage1.Clear()
        End If
    End Sub
 เป็นส่วนของการบรรทึกเท่านั้นครับ รบกวนผู้รู้ด้วยครับ
 ตัวแปรชนิด byte คือ EnrollData ครับ
 
 ปล. มีอาจารย์ท่านหนึ่งแนะนำให้ใช้ String Builder มาครับ
 
 ขอบคุณครับ
 
 
 
 Tag : .NET, MySQL, VB.NET
 
 
 |  
            | 
 ประวัติการแก้ไข
 2011-02-10 11:39:49
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2011-02-10 11:38:05 | By :
                          ppanchai | View :
                          2508 | Reply :
                          4 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองเลี่ยงใช้เป็น parameter ดูครับ ไม่รู้จะใช้ได้หรือป่าวนะครับ ลองดู
 
 
 sql = "Insert into fingerprint(fid, uname, ftemplate, fmodify) values(NULL, '" & retName & "', @EnrollData , '" & dates & "')"
 
 cmd = New MySqlCommand(sql, conn)
 
 cmd.Parameters.Clear()
 cmd.Parameters.Add("@EnrollData", MySqlDbType.Binary).Value = EnrollData
 
 cmd.ExecuteNonQuery()
 conn.Close()
 conn.Dispose()
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-02-10 13:23:04 | By :
                            mrgame |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ยังไม่ได้เลยครับ มีวิธีอื่นไหมครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-02-10 17:24:46 | By :
                            ppanchai |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | 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
 Go to : ASP.NET MySQL BLOB Binary Data and Parameterized Query
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2011-06-02 18:18:15 | By :
                            webmaster |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |