Advertisement
| 06.14.2008 at 03:05AM PDT, ID: 23484854 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: |
Public Function InsertImageToBLOB(ByVal QueryString As String, ByVal FieldName As String, ByVal PictureBox As DevExpress.XtraEditors.PictureEdit) As Integer
Dim ms As MemoryStream = New MemoryStream '// Create a new memory reader
Dim bytBLOBData() As Byte '// Create a byte array to store picture
Dim intBytes As Integer = 0 '// Size of picture
Dim iAffectedRows As Integer = 0 '// Number of affected rows
Try
PictureBox.Image.Save(ms, ImageFormat.Jpeg) '// Get Image from picturebox
intBytes = CInt(ms.Length - 1) '// Calulate byte size of image
ReDim bytBLOBData(intBytes) '// Set size if image byte array
ms.Position = 0 '// Start position for reader
ms.Read(bytBLOBData, 0, CInt(ms.Length)) '// Read the image into the bytBLOBData variable
ms.Close() '// Close reading stream
Catch ex As Exception
Throw
End Try
'// The "Using" block will automatically dispose of the connection when we're finished
Using MyConnectionMySQLOpen As New MySqlClient.MySqlConnection(m_strConnectionString)
Try
Dim prm As New MySql.Data.MySqlClient.MySqlParameter( _
"@" & FieldName, _
MySql.Data.MySqlClient.MySqlDbType.Blob, _
bytBLOBData.Length, _
ParameterDirection.Input, _
False, 0, 0, Nothing, DataRowVersion.Current, bytBLOBData)
'// Open the DB connection
MyConnectionMySQLOpen.Open()
'// Create a new command object
Dim cmd As New MySqlClient.MySqlCommand()
'// Set command properties
With cmd
.Connection = MyConnectionMySQLOpen
.CommandType = CommandType.Text
.CommandText = QueryString
.Parameters.Add(prm)
End With
'// Execute the SQL query with the command object, and get the affected rows in the DB back
iAffectedRows = cmd.ExecuteNonQuery()
'// Close the connection
MyConnectionMySQLOpen.Close()
Catch MyException As MySqlException
Throw
Catch ex As Exception
Throw
Finally
'// Close connection if an exception was thrown before the connection could close
If MyConnectionMySQLOpen.State = ConnectionState.Open Then
MyConnectionMySQLOpen.Close()
End If
End Try
End Using
Return iAffectedRows
End Function
Public Function GetBLOBImage(ByVal TableName As String, ByVal FieldName As String) As Integer
'// Create the SQL query
Dim QueryString As String = "SELECT " & FieldName & " FROM " & TableName
Dim iAffectedRows As Integer = 0 '// Number of affected rows
Dim rawData() As Byte
Dim FileSize As UInt32
Dim fs As FileStream
'// The "Using" block will automatically dispose of the connection when we're finished
Using MyConnectionMySQLOpen As New MySqlClient.MySqlConnection(m_strConnectionString)
Try
'// Open the DB connection
MyConnectionMySQLOpen.Open()
'// Create a new command object
Dim cmd As New MySqlClient.MySqlCommand()
'// Set command properties
With cmd
.Connection = MyConnectionMySQLOpen
.CommandType = CommandType.Text
.CommandText = QueryString
End With
'// Execute the SQL query with the command object, and get the affected rows in the DB back
Dim myData As MySqlDataReader = cmd.ExecuteReader
'// Close the connection
MyConnectionMySQLOpen.Close()
If Not myData.HasRows Then Throw New Exception("There are no BLOBs data")
myData.Read()
FileSize = myData.GetUInt32(myData.GetOrdinal("file_size"))
rawData = New Byte(CInt(FileSize)) {}
myData.GetBytes(myData.GetOrdinal(FieldName), 0, rawData, 0, CInt(FileSize))
fs = New FileStream("C:\newfile.png", FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(rawData, 0, CInt(FileSize))
fs.Close()
Catch MyException As MySqlException
Throw
Catch ex As Exception
Throw
Finally
'// Close connection if an exception was thrown before the connection could close
If MyConnectionMySQLOpen.State = ConnectionState.Open Then
MyConnectionMySQLOpen.Close()
End If
End Try
End Using
Return iAffectedRows
End Function
|
Advertisement