.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Image store in Database SQL SERVER

Posted By: DPK     Posted Date: September 11, 2008    Points:2   Category :ASP.Net
hello all, I am getting this error while storing an image to the database ... My code is below from... pls help me here... what the wrong i am doing here....

ERROR IS:
===========================================================
An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
The name "System.Byte" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
================================================================

And my code is:
====================================
string File1 = Server.MapPath("DanceTwo.GIF");
FileStream FS;
FS = File.Open(File1, FileMode.Open);

//a byte array to read the image equle the image size.
byte[] ImgByte = new byte[FS.Length];
FS.Read(@ImgByte, 0, Convert.ToInt32(FS.Length));
FS.Close();

//now insert that image in database.
CON = new SqlConnection();
CON.ConnectionString = ConfigurationManager.ConnectionStrings["ConWeb"].ConnectionString;
SqlCommand CMD = new SqlCommand();
CMD.Connection = CON;
CMD.Connection.Open();

CMD.CommandText = "insert into TabImg values(" + ImgByte + ", 'Aadi Image')";
CMD.ExecuteNonQuery();

CMD.Connection.Close();
=============================================


thanks in advance...

Responses
Author: Pankaj Mishra             
Posted Date: September 11, 2008     Points: 5   

HI,
Is there only two columns in your "TabImg" table if no then change you sql Query like this

insert into TabImg (ImageColName,ImageDescName) values(" + ImgByte + ", 'Aadi Image' //Give the name of the column in insert statement

Cheers
Panakj

Author: DPK             
Posted Date: September 11, 2008     Points: 5   

thanks for reply... I dont think that can be issue becoz both statements mean same concept but I tried as u said... still getting same error.....

Author: DPK             
Posted Date: September 11, 2008     Points: 5   

thanks for reply... I dont think that can be issue becoz both statements mean same concept but I tried as u said... still getting same error.....

Author: Pankaj Mishra             
Posted Date: September 11, 2008     Points: 5   

Hi,
Try like this you have to declare explicit SQL Parameter for the byte. Example is here

http://www.dotnetspark.com/DotNetResource/35-read--write-image-into-sql-server-in-asp-net-part---1.aspx

Cheers
Pankaj

Author: DPK             
Posted Date: September 11, 2008     Points: 5   

ya thanks pankaj its working fine now :)

Author: Santosh             
Posted Date: October 16, 2009     Points: 5   

plz follow below link
http://www.dotnetspark.com/kb/Content.aspx?id=938
Regards
Santosh



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend