i've got this piece of coding. i need help with opening a picture box and then saving it as OLE Object in access DB
How would i massage this code tho fit in? -
try
-
{
-
//save image to byte array and allocate enough memory for the image
-
byte[] imagedata = image.ToByteArray(new Atalasoft.Imaging.Codec.JpegEncoder(75));
-
-
//create the SQL statement to add the image data
-
myConnection = new OleDbConnection(CONNECTION_STRING);
-
OleDbCommand myCommand = new OleDbCommand("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', ?)", myConnection);
-
OleDbParameter myParameter = new OleDbParameter("@Image", OleDbType.LongVarBinary, imagedata.Length);
-
myParameter.Value = imagedata;
-
myCommand.Parameters.Add(myParameter);
-
-
//open the connection and execture the statement
-
myConnection.Open();
-
myCommand.ExecuteNonQuery();
-
}
-
finally
-
{
-
myConnection.Close();
-
}
-
Here is my open file code (works fine) -
public void openBMP(String filename)
-
{
-
//Declare the OpenFileDialog as a new OpenFileDialog.
-
OpenFileDialog openFileDialog = new OpenFileDialog();
-
//Declare the PictureBox as a new PictureBox
-
//PictureBox pic = new PictureBox();
-
//Set the openFileDialog's Filter.
-
openFileDialog.Filter = "Bitmap Image|*.bmp|All Files|*.*";
-
//Set the openFileDialog's FileName to nothing.
-
openFileDialog.FileName = "";
-
string path = "";
-
//Show the openFileDialog
-
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
-
{
-
//To do code if the Open button was pressed
-
//Use something like:
-
filename = openFileDialog.FileName;
-
pic.Image = Image.FromFile(filename);
-
pic.Size = new System.Drawing.Size(280, 140);
-
pic.SizeMode = PictureBoxSizeMode.CenterImage;
-
path = System.IO.Path.GetDirectoryName(openFileDialog.FileName) + "\\" + openFileDialog.FileName;
-
FullFileName = openFileDialog.FileName;
-
txtComp_Image.Text = path;
-
-
-
}
-
else
-
{
-
return;
-
}
-
and here is my insert code -
string UpdateStr = "";
-
if(count == 0)
-
{
-
-
-
int i = 1;
-
UpdateStr = "Insert into qx_Company " +
-
"(AST__ID, AST__NAME, AST__STREET, AST__TOWN, AST__CITY, AST__TEL, AST__FAX, AST__MAIL, AST__SITE, AST__POST, AST__PATH )" +
-
"values('" + i.ToString() + "','" + txtComp_Name.Text + "','" + txtComp_Street.Text + "','" + txtComp_Town.Text + "','" + txtComp_City.Text + "','" + txtComp_Tel.Text + "','" + txtComp_Fax.Text + "','" + txtComp_Email.Text + "','" + txtComp_Website.Text + "','" + txtComp_Box.Text + "','" + txtComp_Image.
-
as i said, i just want to save the picture as a OLE Object
Help is much appreciated.
1 11576
Notice how in the first piece of code that they use parameters instead of long string concatenation? - OleDbCommand myCommand = new OleDbCommand("INSERT INTO Atalasoft_Image_Database (Caption, ImageData) VALUES ('" + txtCaption.Text + "', ?)", myConnection);
-
OleDbParameter myParameter = new OleDbParameter("@Image", OleDbType.LongVarBinary, imagedata.Length);
-
myParameter.Value = imagedata;
-
myCommand.Parameters.Add(myParameter);
When this code is executed, the OleDbCommand will replace the "?" with the parameter's value...which in this case is a byte[].
In the open file part of your code, you should use a System.IO.FileStream to read the file's contents into a byte[] and use that for the parameter to insert into the DB.
Make sure you always close any Streams you open.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Sergiusz Michalski |
last post by:
Hallo!!
According to my previous post with popups hanging, now I'm trying to bypass
this strange behaviour using loading JavaScript image not by image.src=URL
but straight away from stream using HTTP GET method.
The problem is, how to assign stream from downloaded image (ex. GIF89a) to a
JavaScript Image object ?
Below is my code with...
|
by: Dev |
last post by:
Dear Friends,
I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network.
I want display the image into picturebox without saving image files into Hard disk. Just display the image into PictureBox.... Is it Possible? If so how do to this?
|
by: Deepak C.G via .NET 247 |
last post by:
I want to dispose the image object in my child form, unless I won't dispose this
object i can't delete the image file in my folder.
I get this error in MDIparent form
"An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll"
"Additional information: Invalid parameter used."
Here is my code:-
|
by: Martin Honnen |
last post by:
I was playing around with canvas support in recent Safari, Mozilla and
Opera (only version 9 preview) but run into issues with Safari related
to the very old DOM Level 0 Image object for preloading images.
When doing e.g.
var img = new Image();
img.onload = function (evt) {
alert(this);
};
img.src = 'whatever.gif';
|
by: Jianwei Sun |
last post by:
I had a question on how to bind an image object to the ObjectDataSource.
Basically, I use an ObjectDataSource to insert a record to sql server. I
want to include an image object as a parameter in the record I want to
insert.
I want to find right way to construct the parameter object.
Something like that:
| |
by: Rob T |
last post by:
I made an image slideshow with precaching that uses three overlapping
div tags that each contain an img tag that can be accessed using
getElementById(). If imgObj is my image object, I change imgObj.src to
the image URL and I'm checking imgObj.complete to see if it has been
loaded. The problem is that when I change an imgObj that previously...
|
by: Brian |
last post by:
I have a windows forms project done in vb.net. One of the forms
creates graphs based on the data supplied to it. I want to take
multiple graphs and paste them into a larger Image object. I already
have the code to create a single graph. I'm hoping that I can take
these graphs and paste them into a given spot in the larger image.
I've...
|
by: luigidavinci |
last post by:
Hi there, I just found these forums and several questions I had have been answered by just reading the posts but this one.
I have simplified my code in order to just get to the point with my question.
This is my html code:
<html>
<head>
</head>
<body>
|
by: norseman |
last post by:
Daniel de Sousa Barros wrote:
================================================
Click Start/settings/control panel/system/advanced/settings(in \
performance area)/advanced/change
set System managed size on
click SET box to right of above line
click positives (OK APPLY etc.) all way out, system will probably reboot
|
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...
|
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...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |