473,598 Members | 3,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BLOB: Please help me figure out wrong is goin wrong

28 New Member
I'm newbie to .net and currently learning to use BLOB to insert image into database
What i'm facing is i dont know what is going wrong to make me continue getting this error:
An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in system.data.dll

Hope to get some direction from all senior

the following is my code:
_______________ _______________ _______________ _______________ ___
Expand|Select|Wrap|Line Numbers
  1. Private Function OpenConn() As Boolean
  2.         myCN = New OleDb.OleDbConnection 
  3.         Dim sConnString = "Provider=MSDAORA.1;User ID=123;Password=123;Data Source=test" '
  4.         myCN.ConnectionString = sConnString
  5.         myCN.Open()
  6.         OpenConn = True
  7.  
  8.     End Function
  9. ________________________________________________________________
  10.     Private Sub CloseConn()
  11.         If myCN.State = ConnectionState.Open Then
  12.             myCN.Close()
  13.         End If
  14.     End Sub
  15. _________________________________________________________________
  16.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  17.         Dim openDlg As OpenFileDialog = New OpenFileDialog
  18.         openDlg.Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.jpg"
  19.         Dim filter As String = openDlg.Filter
  20.         openDlg.Title = "Open a Bitmap File"
  21.         If (openDlg.ShowDialog() = DialogResult.OK) Then
  22.             curFileName = openDlg.FileName
  23.             TextBox1.Text = curFileName
  24.             With PictureBox1
  25.                 .Image = Image.FromFile(openDlg.FileName)
  26.                 .SizeMode = PictureBoxSizeMode.CenterImage
  27.  
  28.             End With
  29.  
  30.         End If
  31.     End Sub
  32. ________________________________________________________________
  33.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  34.  
  35.         OpenConn()
  36.  
  37.         Dim cmd As OleDbCommand
  38.         Dim fs As FileStream
  39.  
  40.         fs = New FileStream(curFileName, FileMode.Open, FileAccess.Read) ' Read a bitmap contents in a stream
  41.         Dim b(fs.Length - 1) As Byte
  42.         fs.Read(b, 0, b.Length)
  43.         fs.Close()
  44.  
  45.         cmd = New OleDbCommand("INSERT INTO test (filename, filesave) Values ('" + TextBox1.Text.Substring(TextBox1.Text.LastIndexOf("\") + 1+ "','?')", myCN)
  46.         cmd.Parameters.Add("filesave", OleDbType.VarBinary)  
  47.         cmd.Parameters.Item(0).Value() = b  
  48.         cmd.ExecuteNonQuery()
  49.         CloseConn()
  50.  
  51.         MsgBox("New Record inserted.")
  52.         End
  53.     End Sub
  54. __________________________________________________________________
I'm thinking is it my last few line (SqlCommand) going wrong?
but don't know how to modify it
Please give me some direction, thanks in advance
** im using microsoft visual studio .net 2003 and 1.1 framework
Sep 22 '08 #1
5 1553
Plater
7,872 Recognized Expert Expert
What line throws the exception?
Sep 22 '08 #2
simonyong
28 New Member
What line throws the exception?



hello, Plater

the line throws the exception is :
cmd.ExecuteNonQ uery()

so i think it may caused by the incorrect command text
Thanks.
Sep 23 '08 #3
Plater
7,872 Recognized Expert Expert
Yes, I don't believe your command paramaters and sql string are correct.
The exception message should have had more details about WHAT it didn't like?
Sep 23 '08 #4
simonyong
28 New Member
Yes, I don't believe your command paramaters and sql string are correct.
The exception message should have had more details about WHAT it didn't like?

there are just displayed :
An unhandled exception of type 'System.Data.Ol eDb.OleDbExcept ion' occurred in system.data.dll
Sep 24 '08 #5
Plater
7,872 Recognized Expert Expert
Well that is a managed exception, so there is more to it then that. Try debugging it?
Sep 24 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
21905
by: Thierry | last post by:
Hello, I do have a mysql database with a BLOB column. What is the proprest way to read this column ? Thx, Thierry
1
5632
by: sams | last post by:
Iam posting this after trying many tutorials in the NG and failing to retrieve the blob out of a record. So please bear with me before before you pull the water hose or flame throwers ...... I can upload a Jpeg image file perfectly. Iam using this snippet to do that.. <!-- addpic.php snippet !--> .... $file = fopen($_FILES, "rb");
3
3134
by: NotGiven | last post by:
I am researching the best place to put pictures. I have heard form both sides and I'd like to know why one is better than the other. Many thanks!
3
10441
by: adam | last post by:
Hi, I have an issue that i just cant seem to figure out hope some one can help. right i am getting people to input the own images directly into a blob within a mysql database. then on the next page i want to display the image with in a nicely formatted html table so i can put the image where i choose on the page *this code is only putting the image on the top of the page and wont let me output any other text etc*
0
3418
by: Corrine | last post by:
I am trying to pass a temporary BLOB that I've created in Java, to a PLSQL function that modifies it, and then to retrieve this modified value back to Java, all using JDBC. I can't figure out how to get the modified BLOB object back to Java after the PLSQL block has finished executing. I do: BLOB bl = BLOB.createTemporary(db,true,BLOB.DURATION_SESSION);
4
2236
by: Ellen K | last post by:
Hi all, It was my understanding (Please correct me if I'm wrong on this!) that BLOB data actually reside on their own separate pages and a BLOB field only holds a pointer to the location of the actual data, therefore the BLOB data per se would not get written to the log, only the pointer would be written. If log shipping works by applying the transaction log to the standby database, then what happens to the BLOB data?
9
7972
by: matt | last post by:
hello, im doing my first ASP.NET app that inserts & retrieves files from Oracle (no need for a discussion on *that*!). i learned first-hand of the somewhat awkward technique for inserting binary data into an Oracle BLOB column via ADO.NET. since my files are larger than 33k, it seemed had to use this technique: http://support.microsoft.com/default.aspx?scid=kb;en-us;322796
4
4230
by: skunapareddy | last post by:
I am needing to read a blob from database and pass it to another java program. I researched internet and found a program that reads a file on the client pc and gives bytes, but when I modified the code to read a blob from DB I am not having any luck, I am running this java programs using JDEVELOPER. Can anyone please give me some help? The code is as follows: ... private static byte getBytesFromBlob(Blob blob) throws Exception { ...
16
6655
by: wizard | last post by:
Here is a piece of code below for writing and reading blobs in SQLITE database. I ' ve a problem to read from blob struct called 'Points' Any help would be appreciated Reagards Greg #include <stdlib.h> #include <stdio.h>
0
7987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7899
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8392
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8397
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6718
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3939
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1504
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.