 |
|
 |
Hello Kazim Sir,
I have converted your code into VS2008 and compiled.
It compiled and run successfully but when try save the images it through an error saying-
"ExecuteNonQuery requires an open and available connection. The connections current state is closed" but when I debug the code it shows the connection is open.
while the line
int iresult = this.sqlCommand1.ExecuteNonQuery();
shows the error.
Please Help. It Urgent!!!!
|
|
|
|
 |
|
 |
double check that you open your connection before the "ExecuteNonQuery()" call. sqlConnection1.Open(); -------------------------- only one life it'll soon be past only what's done for Christ will last
|
|
|
|
 |
|
 |
Can u tell me the directories used.
Thanks & Regards
Rahul
|
|
|
|
 |
|
|
 |
|
 |
I recently needed to export the photos from the Club web site template pages. Here is a small snipet. Maybe it helps someone ...
Example connection string:
<add key="ConString" value="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\...\www.myweb.com\App_Data\Club.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" />;
private void buttonLoadAll_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmdSelect = new SqlCommand("select id, album, origimage from images", this.sqlConnection1);
da.SelectCommand = cmdSelect;
da.Fill(ds, "tab");
foreach (DataRow dr in ds.Tables["tab"].Rows)
{
int id = (int)dr["id"];
int album = (int)dr["album"];
byte[] barrImg = (byte[])dr["origimage"];
FileStream fs = new FileStream(album + "_" + id + ".jpg", FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
}
}
|
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I am getting an Out of Memory error on calling this line of code
Image.FromFile(savedFilename);
Please help
|
|
|
|
 |
|
 |
I am getting an Out of Memory error on calling this line of code
Image.FromFile(savedFilename);
Please help
|
|
|
|
 |
|
 |
Kazim,
Thank you for your post. It actually works and it is very simple for my simple mind...
J.
|
|
|
|
 |
|
 |
Thanks a lot
=============
NITIN SAWANT
=============
|
|
|
|
 |
|
 |
Hi
This is a nice post, I have got everything working except for the fact that it creates temporary files, how do I delete them? I have tried a few techniques and end up with an error saying
Additional information: The process cannot access the file "C:\???\ImageSaveInDataBase\bin\Debug\128968083431232299" because it is being used by another process.
It creates temporary files when loading and when retrieving.
NB.
if(File.Exists(fs.Name))
{
File.Delete(fs.Name); --Exception caused here
}
|
|
|
|
 |
|
|
 |
|
 |
I modified the .sql script a bit and then ran it. I then added my connection string to the app.config file.
I ran the app and was able to save and load from SQL Express, SQL 2005 AND SQL 2008.
I cut & pasted the part of the code I needed, modified the code and params a bit to match my table and I was up and running in no time. This little article saved me some time for sure.
Worked like a charm for my ASP.NET administration page for loading images.
Thanks dude.
-CrazyTasty
p.s. If we need to save and load large image sizes, make sure memory is allocated correctly and objects are destroyed immediately after use.
p.s.s. Cleaning up the temp file(s) can be done a number of ways. Either use an InterOp method for grabbing the handle and removing it that way, or remove anything with 0 bytes when exiting the program.
p.s.s. Also, if we are to store and retrieve a lot of images (where some are large maybe) across the network and tiers alike, storing images all together is probably a bad idea due to possible performance issues. There are definitely Pros and Cons out there to be aware of.
modified on Wednesday, August 19, 2009 2:45 AM
|
|
|
|
 |
|
 |
This article helped me so much
Thank you
|
|
|
|
 |
|
 |
Can you help me in writing the similar code in .net 2003
|
|
|
|
 |
|
|
 |
|
|
 |
|
|
 |
|
 |
How can i do error checking for Save image, for example, the name is already used. So how can i do checking for the database?
|
|
|
|
 |
|
 |
hi,thanks the code works really fine
but I have an issue........
I hv a table with photo as a column with image datatype in sqlserver2005
Now the code below is used to save the image in this column actually record for the student has already been inserted now i want to only update this field..
ssql = "update Students set Photo=@Pic where ID='2'
cmd.CommandText = ssql
cmd.Parameters.Add("@Pic",System.Data.SqlDbType.Image)
cmd.Parameters.Item("@Pic").Value = barrImg
cmd.ExecuteNonQuery()
This code does execute without any error but it inserts null value..
The variable barrimg has the same sense that is represented in this code.
please help me out as where am I going wrng.........
Its URGENT........... :
|
|
|
|
 |
|
 |
Hi
I am facing a problem, i have a gridview and i want to add gridview's data to sql server database table. how can it possible.
thanx
naresh rajput
|
|
|
|
 |
|
 |
I m also facing same problem like that.
anyone can help plz
|
|
|
|
 |
|
 |
hi sir,
this code workds fine but have some difficulties. whenever i want to see the imaged it display a message "C:documents and setteing/..../ file already exists". and it is becoze when we view a photo then a temporary file is created autometically. please tell me how to solve this problem and how to delete autometically the file which is created autometically.
thanks
|
|
|
|
 |
|
 |
Replace the following lines
string strfn=Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs=new FileStream(strfn,FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg,0,barrImg.Length);
fs.Flush();
fs.Close();
pictureBox1.Image=Image.FromFile(strfn);
With the following line using the memory stream no need to incur the overhead of writing to disk and reading from disk.
pictureBox1.Image=Image.FromStream(new MemoryStream(barrImg));
|
|
|
|
 |