p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > C# and C > C# 1.0 > C#
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2003, 07:14 AM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default Insert Image to MS-SQL

Hi there:
Im going to insert an Image into MS-SQL Server 2000, could anyone give me a sample!

I use the code that I've useing for other tables but I guess I need something more for inserting Images to Database!
Bye the way Im using DataSet & DataAdapter.

Any help is appreciated.

Always:),
Hovik Melkomian.
__________________
Always[:)],
Hovik Melkomian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 11th, 2003, 01:59 AM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default

I found my amswer guys!!!

Always:),
Hovik Melkomian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 30th, 2003, 10:20 PM
Registered User
Points: 25, Level: 1
Points: 25, Level: 1 Points: 25, Level: 1 Points: 25, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi melvik,

I trying to do the same: inserting an image into MS-SQL.
Can you show me your sample code?

Yeah, i follow the instructions on
http://www.developerfusion.com/show/3905/1/

But I stumble on it. Here is the error message that I got:
-------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 68: imgStream = UploadFile.PostedFile.InputStream;
-----------------------------------------------------------------

I can't figure what I miss. Can anyone help?

Thanks.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 30th, 2003, 10:24 PM
Friend of Wrox
Points: 2,244, Level: 19
Points: 2,244, Level: 19 Points: 2,244, Level: 19 Points: 2,244, Level: 19
Activity: 7%
Activity: 7% Activity: 7% Activity: 7%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
Default

I am new to C# also but I think you need to use the datatype "Stream".

Stream imgStream = UploadFile.PostedFile.InputStream;






======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old November 1st, 2003, 12:49 AM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default

All r the same as u do for ur text fields but Image part! Here u will just need to change the format of Image to Bitmap Object.
Anyway its what I've done for adding a pic to my dataset using DataAdapter & StoredProcedure on SQL-Server 2000.

Code:
        private void buttonScan_Click(object sender, System.EventArgs e)
        {
            if( DialogResult.OK == FileOpenDlg.ShowDialog() )
            {
                string file = FileOpenDlg.FileName;
                System.IO.FileStream stream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] buffer = new byte[stream.Length];
                stream.Read(buffer, 0, (int)stream.Length);
                stream.Close();
                string strName = System.IO.Path.GetFileNameWithoutExtension(file);

                //SavePic
                DataRow PicRow;
                PicRow = dsDabir1.Tables["Images"].NewRow();
                PicRow["IId"] = 22;
                PicRow["ImgPage"] = 1;
                PicRow["ImgPic"] = buffer;
                dsDabir1.Tables["Images"].Rows.Add(PicRow);
                sqlDataAdapterPix.Update(dsDabir1, "Images");
                buffer = null;

                //ShowPic
            }//if
        }
Always:),
Hovik Melkomian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old November 3rd, 2003, 09:13 PM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to uponline_aom
Default

 Up

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old November 9th, 2003, 01:56 AM
Registered User
Points: 25, Level: 1
Points: 25, Level: 1 Points: 25, Level: 1 Points: 25, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Melvik,

I got it now.
Thanks for your help.

Vivi

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old November 9th, 2003, 02:32 AM
Friend of Wrox
Points: 3,152, Level: 23
Points: 3,152, Level: 23 Points: 3,152, Level: 23 Points: 3,152, Level: 23
Activity: 20%
Activity: 20% Activity: 20% Activity: 20%
 
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via Yahoo to melvik
Default

pleasure 2 be useful.

Always:),
Hovik Melkomian.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old June 15th, 2006, 10:04 AM
Registered User
 
Join Date: Jun 2006
Location: , PA, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rodmcleay
 I am new to C# also but I think you need to use the datatype "Stream".

Stream imgStream = UploadFile.PostedFile.InputStream;






======================================
They say, best men are moulded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
I'm running into the same type of problem but I do have my code with the Stream in it.

I'm getting a System.NullReferenceException: Object reference not set to an instance of an object.

I'd put all my code here but you guys would probably die trying to read it all. I did use the reference link to get my code (http://www.developerfusion.com/show/3905/5/) and even though I used that code I'm still getting the error.

Here's my click function (and yes my item is named BtnUpload not UploadBtn

any suggestions??
        public void BtnUpload_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) //Save Image
            {
                Stream imgStream = UploadFile.PostedFile.InputStream;
                int imgLen = UploadFile.PostedFile.ContentLength;
                string imgContentType = UploadFile.PostedFile.ContentType;
                string imgName = txtAdCode.Value;
                byte[] imgBinaryData = new byte[imgLen];

                int n = imgStream.Read(imgBinaryData, 0, imgLen);

                int RowsAffected = SaveToDB(imgName, imgBinaryData, imgContentType);
                if (RowsAffected > 0)
                {
                    Response.Write("<br />Image Saved<br />");
                }
                else
                {
                    Response.Write("<br />An error has occurred, please upload again<br />");
                }
            }
        }

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert image in sql 2000 mangala SQL Server 2000 18 December 17th, 2007 06:11 AM
MS ACCESS 2003 FRONTEND AND MS SQL SERVER 2005 DB mohankumar0709 SQL Server 2005 3 March 23rd, 2007 01:48 AM
Need help on MS SQL Server 005 Express INSERT cmd VictorVictor ASP.NET 2.0 Professional 7 November 23rd, 2006 02:12 AM
how to insert the path of image in sql server hoailing22 ASP.NET 1.0 and 1.1 Basics 0 February 28th, 2006 03:37 AM
How to insert path of the image in sql server hoailing22 SQL Server 2000 0 February 28th, 2006 03:32 AM



All times are GMT -4. The time now is 03:43 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc