|
Hi JON Prabhu
I am using ASP.NEt,VB.NET to save and reteive the images from DB, i recently posted in Vb.NEt forum the Same and as Christian suggested i used file system to retrive image using file system and only storing path in DB. it getting saved and retrive.
But still i am trying to know how to retrieve the image from DB here is the sample code i have used to retrive image form DB but i am only getting the imagebox with crossed but not image is getting showed.
<br />
<br />
Private Sub btnRetrive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrive.Click<br />
Dim sqlconn As New SqlConnection(ConfigurationSettings.AppSettings("BILL_CONSTR"))<br />
Dim sqlcommand As New SqlCommand("select PersonImage from dbo.Person where PersonID=3", sqlconn)<br />
Try<br />
sqlconn.Open()<br />
Dim SqlData As SqlDataReader<br />
SqlData = sqlcommand.ExecuteReader(CommandBehavior.CloseConnection)<br />
Do While (SqlData.Read())<br />
Response.ContentType = "image/gif"<br />
Response.BinaryWrite(SqlData.Item("PersonImage"))<br />
Loop<br />
sqlconn.Close()<br />
Catch SQLex As SqlException<br />
Response.Write("Insert Failed. Error Details are: " & SQLex.ToString())<br />
<br />
End Try<br />
End Sub<br />
<br />
<br />
<br />
<br />
sathimailin
|
|
|
|
|
The code which you have written seems correct. It should probably work. Just put a break point and do a step-wise execution and check whether the execution reaches the code Response.Binarywrite() .
Regards - J O H N -
|
|
|
|
|
hi Prabhu,
Its getting executed and i am getting a page with only image box not an image shown but passes all the code lines and when i right click and see the properties
it shows not avalable.
sathimailin
|
|
|
|
|
I suppose the Image is not Uploaded properly. Just Try uploading a new Image file and check with it. below is a sample code which works well in one of my project.
Response.ClearHeaders()<br />
Response.Cache.SetNoStore()<br />
Response.ContentType = "image/gif"<br />
Response.BinaryWrite(lImageDataset.Tables(0).Rows(0)(0))
Regards - J O H N -
|
|
|
|
|
THanks Jon
i will try with new one
|
|
|
|
|
You are welcome
Regards - J O H N -
|
|
|
|
|
Hi Jon
yes ,Thanks for the help , i have got the image from DB but altered with some codes please check this
but still i have to go around with some things like i am getting only one image for display.so i am working on it if u have some idea please let me know.
<br />
'Using DB To Store Image IN Database<br />
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click<br />
<br />
Dim oStrPostedFileName, oStrFileName<br />
Dim oBinaryReader As BinaryReader<br />
Dim fs As FileStream<br />
<br />
intImageSize = fileUploadCTRL.PostedFile.ContentLength<br />
strImagetype = fileUploadCTRL.PostedFile.ContentType<br />
ImageStream = fileUploadCTRL.PostedFile.InputStream<br />
oStrPostedFileName = System.IO.Path.GetFullPath(fileUploadCTRL.Value)<br />
<br />
Dim ImageContent(intImageSize) As Byte<br />
intsize = ImageStream.Read(ImageContent, 0, intsize)<br />
<br />
<br />
<br />
fs = New FileStream(oStrPostedFileName, FileMode.Open, FileAccess.Read)<br />
Dim MyData(fs.Length) As Byte<br />
<br />
oBinaryReader = New BinaryReader(fs)<br />
ImageContent = oBinaryReader.ReadBytes(CType(fs.Length, Integer))<br />
oBinaryReader.Close()<br />
fs.Close()<br />
<br />
Dim sqlconn As New SqlConnection(ConfigurationSettings.AppSettings("BILL_CONSTR1"))<br />
sqlconn.Open()<br />
<br />
Dim sqlcommand As New SqlCommand("sp_Image", sqlconn)<br />
sqlcommand.CommandType = CommandType.StoredProcedure<br />
sqlcommand.Parameters.Add(New SqlParameter("@PersonImage", SqlDbType.Image))<br />
sqlcommand.Parameters("@PersonImage").Value = ImageContent<br />
sqlcommand.ExecuteNonQuery()<br />
Response.Write("New Image Added Successfully")<br />
End Sub<br />
<br />
'Reteriving From DB<br />
Private Sub btnRetrive_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRetrive.Click<br />
Dim sqlconn As New SqlConnection(ConfigurationSettings.AppSettings("BILL_CONSTR1"))<br />
Dim ds As New DataSet<br />
Dim i As Integer<br />
Dim da As New SqlDataAdapter("select PersonImage from Contacts.dbo.Person where pid in(1,2,3)", sqlconn)<br />
Try<br />
sqlconn.Open()<br />
da.Fill(ds)<br />
For i = 0 To ds.Tables(0).Rows.Count - 1<br />
<br />
Response.ClearHeaders()<br />
Response.Cache.SetNoStore()<br />
Response.ContentType = "image/gif"<br />
Response.BinaryWrite(ds.Tables(0).Rows(i).Item("PersonImage"))<br />
Next<br />
<br />
Catch ex As Exception<br />
ex.Message.ToString()<br />
Finally<br />
sqlconn.Close()<br />
End Try<br />
End Sub<br />
<br />
End Class<br />
i Have three image in DB and need to display.
sathimailin
|
|
|
|
|
Retriving more than one Image and looping through the Images is of no use. Anyway your Response.Binary() will write to the client once. Next time when you again execute the Response.binary() it will overwrite. It would be better if you seperate the Image retriving code in a seperate class file and use it. And Most importantly read some articles about 3-Tier Architecture and try to seperate your DataAccess code from Presentation Layer.
Regards - J O H N -
|
|
|
|
|
hi Jon
Thanks for your reply and Tips i will work on using Layers and if u have any good link for practicing layers let me know i want some links.
sathimailin
|
|
|
|
|
Check this article[^]. Hope It will give you a basic understanding about the N-Tier architecture.
Regards - J O H N -
|
|
|
|
|
|
Hi,
This is from Chandrakanth.
Actually i have done Mailing System.It is working fine.
And i want attach a file with Mail.
How can i attach a file with Mail.
Can any one tell me how to attach a file
Thanks And Regards
Chandrakanth.
Chandrakanth
|
|
|
|
|
System.Web.Mail.MailMessage m = System.Web.Mail.MailMessage();
m.Attachments.Add();
|
|
|
|
|
Hi,
i have the below code in my page.
protected string ConvertPercent(object number)
{
if (number == DBNull.Value)
return "-";
else
if (number == float.Negative)
return "0";
else
return "1";
};
i want the "0" to be return incase NUMBER having negative (exp: -1.236)
i want the "1" to be return incase NUMBER having positive (exp: 1.236)
Please help me......i dont know the syntax for this....thxxx
|
|
|
|
|
VinothRao wrote: protected string ConvertPercent(object number)
{
if (number == DBNull.Value)
return "-";
else
if (number == float.Negative)
return "0";
else
return "1";
};
Is this code working?
If no try following code
this is not a proper way to identify number is negative or positive but it will work.
if(number.ToString().Contains("-"))
return 0;
else
return 1;
best regard
pAthAn
|
|
|
|
|
wow.....so easy the syntax.....thx a lot brooo
no my code wont work becoz actually i just put the syntax there to show clearly what is was looking for....
thx 4 ur code......it works perfectly.....
|
|
|
|
|
Imran Khan Pathan wrote:
if(number.ToString().Contains("-"))return 0;elsereturn 1;
I assume you are taking the **** here? Convert a number to a string, checking if the string starts with a 'minus' symbol to determine if it is negative or not?
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
VinothRao wrote: i want the "0" to be return incase NUMBER having negative (exp: -1.236)
i want the "1" to be return incase NUMBER having positive (exp: 1.236)
if (number < 0)
return 0;
else
return 1;
You need to cast number from object type to float before doing checking
|
|
|
|
|
i did that before.......but was encounter error........
Operator '<' cannot be applied to operands of type 'object' and 'int'
Brooo.....after implement ur code into my page.....got some confusion happen with the result....c below....
Grp1 +0.0071
Grp2 0.0001
Grp3 +0.0047
Grp4 +0.0041
Grp5 +0.0038
Grp6 0.0001
Grp7 +0.0005
for the data 0.0005 it has + sign.......but for data 0.0001 dont have....any idea???
Below is the code.
protected string ConvertRM(object number)
{
if (number == DBNull.Value)
return "-";
else
if (number.ToString().Contains("-"))
return String.Format("{0:F4}", number);
else
return String.Format("+{0:F4}", number);
}
|
|
|
|
|
This all looks very bizarre. Please post a sample of the actual data returned from teh database. Don't format it, just post it here as it is stored in the table. You will get a far better solution than the one you are using at the moment.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
the result i given u is part of the actual result taken from db to aspx page...
in aspx page the syntax is :
<asp:label id="Change1" runat="server" text="<%# ConvertRM(DataBinder.Eval(Container, "DataItem.Change")) %>">
i using datagrid to populate the data's.
anything else u need bro??
|
|
|
|
|
the result i given u is part of the actual result taken from db to aspx page...
in aspx page the syntax is :
<asp:Label ID="Change1" runat="server" Text='<%# ConvertRM(DataBinder.Eval(Container, "DataItem.Change")) %>'></asp:Label>
i using datagrid to populate the data's.
anything else u need bro??
|
|
|
|
|
it seems i cant post the aspx tag.....
|
|
|
|
|
VinothRao wrote: Operator '<' cannot be applied to operands of type 'object' and 'int'
You have to cast the object type to float.
protected string ConvertRM(object number)
{
float FNumber = (float)number;
if ( FNumber < 0 )
return "0";
else
return "1";
}
|
|
|
|
|
Compilation was having error after i put up ur code
It says "Specified cast is not valid"......
|
|
|
|