Welcome to AspAdvice
Sign in
|
Join
|
Help
Steven Swafford: Overworked and Underpaid
Just another simple developer's thoughts!
This Blog
Email
Syndication
RSS 2.0
Atom 1.0
Search
Go
Tags
.NET: ASP.NET
.NET: C#
.NET: VB.NET
C# Code Snippets
Coffee Lounge
CSS Snippets
Current Events
Documents and Templates
Humor
JavaScript Code Snippets
Oracle ODP.NET
VB.NET Code Snippets
XML
Navigation
Home
Blogs
Forums
Photos
Downloads
My Reader
Archives
June 2007 (3)
May 2007 (3)
April 2007 (3)
March 2007 (3)
January 2007 (2)
December 2006 (2)
November 2006 (2)
October 2006 (3)
September 2006 (2)
July 2006 (1)
June 2006 (1)
May 2006 (3)
April 2006 (2)
March 2006 (1)
February 2006 (1)
January 2006 (3)
November 2005 (2)
October 2005 (2)
August 2005 (3)
July 2005 (3)
May 2005 (2)
April 2005 (2)
March 2005 (6)
February 2005 (3)
January 2005 (5)
December 2004 (3)
- My Favorites -
.NET: C# Open Source
CSharp Source.NET
Commendable Blogs
Scott Watermasysk
Dave Sussman
Rob Howard
Scott Mitchell
Wallace B. McClure
Nikhil Kothari
Michael's meanderings
Onion Blog
Tom Hollander's Blog
ScottGu's Blog
Design Patterns
Data & Object Factory
Microsoft Patterns & Practices
Java: Open Source
Java Source.NET
My ASPAlliance Articles
Introducing Windows Management Instrumentation (WMI)
Step-by-Step Process of Creating a Setup and Deployment Project
CodeSnip: Populate a DropDownList with a Stored Procedure
Product Review: PL/SQL Developer
Read and Write BLOB Data to a Database Table with ODP.NET
Using Oracle Data Provider for .NET
CodeSnip: Setting Commonly-Used Tags Programmatically
Break Up an Extensive Web Form into Simulated Multiple Pages
CodeSnip: Sending E-Mail Using SmtpMail
Uploading Files Using a Webform
Customizing Error Pages
Managing Directories in .NET
Using ODP.NET To Insert Multiple Rows Within A Single Round Trip
Understanding The Web Configuration File - Part 1
Retrieving Database Schema Information Using The OleDbSchemaGuid Class
Oracle Developer Tools for Visual Studio .NET
Build a TreeView Control in Less Than Two Minutes with Visual Studio 2005 Beta 2
Create an XML File via PL/SQL
Use Cases and Their Importance
My Resume
MS Word Format
PDF Format
Oracle
JDeveloper 10g
Oracle Power
Oracle Pipeline
UML
UML Resource Page
New article at ASPAlliance titled Read and Write BLOB Data to a Database Table with ODP.NET
By utilizing ODP.NET, Oracle database, and really very little effort you also can store images as a Blob for convenient storage and simple categorization.
[
Read More
]
Share this post:
email it!
|
bookmark it!
|
digg it!
|
reddit!
|
kick it!
|
live it!
Published Wednesday, March 09, 2005 10:05 AM by
sswafford
Filed under:
.NET: ASP.NET
,
.NET: C#
,
.NET: VB.NET
Comments
#
re: New article at ASPAlliance titled Read and Write BLOB Data to a Database Table with ODP.NET
Wednesday, March 09, 2005 10:16 AM by
sswafford
A friend of mind brought up the idea of getting the upload file's checksum. Here is the VB.NET code he provided.
In the UploadButton_Click:
<code>
Byte[] ImageContent = new byte[imgLength];
int intStatus;
int Status = imgStream.Read(ImageContent, 0, imgLength);
Dim myChecksum as string = Me.GetMD5Hash(ImageContent)
// provides a string like "9B-08-7E-2C-6F-DF-4C-EE-B9-7D-BF-47-D4-32-45-79"
// define the sql to perform the database insert
sqlStmt = "INSERT INTO smstestblob (id, photo, author," + "description ) VALUES (smstestblobid_seq.nextval, :1, :2, :3)";
<code>
Separate function so can be called from wherever:
Private Function GetMD5Hash(ByVal RawData() As Byte) As String
Dim myMD5Provider As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim myMD5Hash() As Byte
' i subtract 1 from the length as this is an array that base 0
myMD5Hash = myMD5Provider.ComputeHash(RawData, 0, RawData.Length - 1)
GetMD5Hash = BitConverter.ToString(myMD5Hash)
End Function
As well I created a C# version:
In the UploadButton_Click:
GetCheckSum(ImageContent);
Public static string GetCheckSum(byte[] ImageContent)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] hash = md5.ComputeHash(ImageContent);
string checkSum = BitConverter.ToString(hash);
return checkSum;
}
#
re: New article at ASPAlliance titled Read and Write BLOB Data to a Database Table with ODP.NET
Sunday, March 20, 2005 3:08 PM by
sswafford
The following question was presented to me.
Regarding the following line of code,
sqlStmt = "INSERT INTO smstestblob (id, photo, author," +
"description ) VALUES (smstestblobid_seq.nextval, :1, :2, :3)";
What do the :1, :2, etc represent? When I am executing the SQL I receive an ORA-12704 Char Set Mismatch error.
Well the short answer I provided is these are nothing more than placeholders. I did want to provide a more in depth answer so I turned to an outstanding DBA named Roger Rowe and here is what he had to say.
Suggestion: Don't use numbers as parameter names, use useful names that make sense. I have had problems when these names didn't match the parameter names in procedures. Also, I am not sure, but I believe that oracle has a requirement of variables beginning with alpha characters (I've never seen numbers used in examples from oracle):
sqlStmt = "INSERT INTO smstestblob (id, photo, author,description ) VALUES (smstestblobid_seq.nextval, :pphoto, :pauthor, :pdescription )";
OracleParameter paramImage = new OracleParameter("pphoto", OracleDbType.Blob);
OracleParameter paramAuthor = new OracleParameter("pauthor",OracleDbType.Varchar2, 100);
OracleParameter paramDescription = new OracleParameter("pdescription ", OracleDbType.Varchar2, 500);
TIP: Keep the oracle SQL code (where possible) in packages/procedures so that the oracle dba can tweak the SQL for performance. Also, can assist in problem resolution if all the DBA needs is the parameter values passed.
TIP: Primary Keys should be generated from a database trigger and not rely upon the interface to generate them (especially when they are from a sequence).
However, the email from Chris does not really refer to the question posed. The "ORA-12704" points me to a language difference between the database and the client. This is what may be referred to as the globalization settings (e.g., NLS_LANG) in the ODP.Net documentation.
Suggestion regarding the "ORA-12704" issue identified below:
Remove "not null" requirements on the "smstestblob" table columns (especially the blob column) - if they exist.
Run the code and see if you can get the following SQL to work (i.e., I take out the parameters and add them one at a time):
sqlStmt = "INSERT INTO smstestblob (id, photo, author,description ) VALUES (smstestblobid_seq.nextval, null, :pauthor, :pdescription )";
At this point it becomes a matter of resolving byte translations (i.e., NLS_LANG or OracleDbType value selection).
#
re: New article at ASPAlliance titled Read and Write BLOB Data to a Database Table with ODP.NET
Monday, May 02, 2005 9:03 PM by
sswafford
what abouth writing it to an image control and have ather tings on the page
#
Read and Write BLOB Data to a Database Table with ODP.NET Trackback
Thursday, March 10, 2005 8:50 AM by
TrackBack
Read and Write BLOB Data to a Database Table with ODP.NET Trackback
#
this is very good
Saturday, April 08, 2006 11:17 AM by
this is very good
good related article
#
this is very good
Saturday, April 08, 2006 11:33 AM by
this is very good
good related article
New Comments to this post are disabled