|
|
 |
| 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.
|
 |

October 4th, 2003, 07:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

October 11th, 2003, 01:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
I found my amswer guys!!!
Always:),
Hovik Melkomian.
|

October 30th, 2003, 10:20 PM
|
|
Registered User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

October 30th, 2003, 10:24 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: , , Australia.
Posts: 587
Thanks: 1
Thanked 1 Time in 1 Post
|
|
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.
======================================
|

November 1st, 2003, 12:49 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|

November 3rd, 2003, 09:13 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Up
|

November 9th, 2003, 01:56 AM
|
|
Registered User
|
|
Join Date: Oct 2003
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Melvik,
I got it now.
Thanks for your help.
Vivi
|

November 9th, 2003, 02:32 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
pleasure 2 be useful.
Always:),
Hovik Melkomian.
|

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
|
|
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 />");
}
}
}
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |