Showing posts with label upload. Show all posts
Showing posts with label upload. Show all posts

Friday, March 30, 2012

Saving SQL Express Databases?

Hello,

I have Visual Studio 2005 Professional.

I was wondering if there were any way to save the .dbo databases created in it to upload to my website? Do the databases must be save as a specific filetype according to the website configuration?

Do most people actually connect to their site's database to modify it or something? Or do they usually connect to an external database and then upload it to their site?

Sorry, but I am kind of new to all of this.

Thanks,

Eng

I'm not very clear about your question. What do you mean by '.dbo databases'? Do you mean something like this: 'mySQLInstance.master.dbo'? This is database reference--not real database file; it is used to connect to database. Databases are always seperated from site, and you should connect to database to retrieve data that used in your site.

Wednesday, March 28, 2012

Saving pictures

Is it better to have users that upload pictures have them saved to SQL server or to a folder? I have a site where users enter things that they own (and each item has a unique id) and now I would like to add the functionality to add a picture. I am sure I should use the fileUpload control, but should this save to a folder created for each user or to the SQL record itself? Or possibly a separate SQL table just for pictures?

Thanks for the help.

Images are stored as BLOB data in SQL Server. So if you want to save the pictures in SQL Server, just send the pics as byte arrays to SQL Server, you can find a lot of examples on the internet. And here is a discussion about to BLOB or not, in this post:

http://forums.asp.net/1357936/ShowPost.aspx

Monday, March 26, 2012

Saving files to SQL Server 2000

Someone:
I have the need to upload a file via a webpage and then save that file into the database. I would also like to retrieve it and show it to the user.

Can someone show me an example of how this should be done. Also I am concerned of the pros and cons of saving files in the database. Is there a performance hit on the server? Will it make the database unstable? Has anyone had problems doing this?

Any suggestions, samples, and/or help are welcome.What kind of files are you attempting to save to the database, images?
Yes, there is a performance hit by placing the file into the database, and you are also increasing the size lots. Remember, if you have 100 rows of data in the table that stores the image in a column and you only have actually 2 images it is saving space for all 100 rows to have an image in there. I really don't think it will make the database unstable, but storing files in the physical folders of the application just seem like a better idea to me. Perhaps in SQL server Yukon this will change since I hear you can store objects in it.|||A database is not a file store. While SQL Server can store binary data, this is not as efficient as storing files in a file system.

File system = designed for storing files
Database = NOT designed for storing files.

Don't do it.|||Pierre:
Thanks for your comments. I have to say that I agree with you. However there are instances that storing a file in the database is more compelling than the file system and you have to weigh both options. Hence my post.

-SosaWISE

Friday, March 23, 2012

Saving Data and retrieving it from the database

Heres my requirement from a financial analysis im doing...

I have just calculated an industry averages on financial ratios...Now i wanna upload this industry average to the system...so that I can compare it to the individual companies' averages after calculating a particular company's average; meaning i wanna be able to call the industry average of a particular ratio (eg Current Ratio) after calculating a company's corresponding ratio...Is there a code fragment i can use for this ??

Thanks in advance...

Adam

Hi,

From your description, it seems that you are going to retrieve the industry averages which you stored in database after calculating particular company's averages, right?

I think the code should be based on the data structure. I don't know how do you handle with your data storage in your project? Does each company's average data stored in a table? Where does the industry average data comes from? It comes from manually calculating? If so, what you should do is just save the data into a single data table, when you are going to calculate each company's average, retrieve the data from your database and save it in a seesion or viewstate to avoid reading the value from database frequently.

Above is just the general idea for your question, as for detail code, it depends on what kinds of way you are going to use, SqlDataReader, Dataset and etc… But the usage of this kinds of data accessing technique can be found at the following address.
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/data/default.aspx

Thanks.

sql

saving an jpeg into database and displaying it into a image box

can some one help me. im using visual studio.net 2005. its a web application.

i have a database with attribute name logo. so i want to upload an image and save it into the database and than display it into the image box to preview how the image looks like.

can some one please help me as i am very new in using C# codes and visual studio.net 2005

Try to google it, you can find many examples.

For a simple example , refer toSaving and Displaying Photos in SQL Server using ASP.NET

|||

Check this article on MSDN:

http://support.microsoft.com/kb/326502/en-us

|||hey h|||

hey hi

sorry i have this errors when i run the codes u recommended me

image.Save(Response.OutputStream,ImageFormat.Jpeg);

they say the 'System.Web.UI.WebControls.Image' does not contain a definition for 'Save'

and the other error is

image =Image.FromStream(memStream);

they say the 'System.Web.UI.WebControls.Image' does not contain a definition for 'FromStream'

Can u please help me

|||You have to importEnterprise Library 2.0 Data Access Application Block if you're following the artilceSaving and Displaying Photos in SQL Server using ASP.NET. You can take a look at the MSDN article if you want to display images without using extra classes.

Wednesday, March 21, 2012

save upload image to db using stored procedure problem

I am trying to save an uploaded image and its associated info to sql server database using a stored procedure but keep getting trouble. When trying to save, the RowAffected always return -1. but when i debug it, I dont' see problem both from stored procedure server
explore and codebehind. it looks to me every input param contains correct value(such as the uploaded image file name, contentType and etc). well, for the imgbin its input param value returns something like "byte[] imgbin={Length=516}". Below is my code, could anyone help to point out what did I do wrong?
Thank you.

================================================
CREATE PROCEDURE [dbo].[sp_SaveInfo]
(
@.UserID varchar(12),
@.Image_FileName nvarchar(50),
@.Image_ContentType nvarchar(50),
@.Image_ImageData image,
@.Create_DateTime datetime)

AS
set nocount on

insert ExpertImage(UserID, Image_FileName, Image_ContentType, Image_ImageData, Image_ReceiveDateTime)
values(@.UserID, @.Image_FileName, @.Image_ContentType, @.Image_ImageData, @.Create_DateTime)
GO

private void Submit1_ServerClick(object sender, System.EventArgs e)
{
if(Page.IsValid)
{
Stream imgStream = File1.PostedFile.InputStream;
int imgLen=File1.PostedFile.ContentLength;
string imgContentType = File1.PostedFile.ContentType;
string imgName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
byte[] imgBinaryData = new byte[imgLen];
int n=imgStream.Read(imgBinaryData, 0, imgLen);
int RowsAffected = SaveInfo(imgName,imgBinaryData, imgContentType);
if(RowsAffected > 0)
{
..
}
else
{
..
}
}
}

public int SaveInfo(string imgName, byte[] imgbin, string imgcontenttype)
{

SqlConnection objConn = new DSConnection().DbConn;
SqlCommand objCMD = new SqlCommand("sp_SaveInfo", objConn);
objCMD.CommandType = CommandType.StoredProcedure;

objCMD.Parameters.Add("@.UserID", SqlDbType.VarChar, 12);
objCMD.Parameters["@.UserID"].Value = txtMemberID.Text.ToString();
objCMD.Parameters["@.UserID"].Direction = ParameterDirection.Input;

objCMD.Parameters.Add("@.Create_DateTime", SqlDbType.DateTime);
objCMD.Parameters["@.Create_DateTime"].Value = DateTime.Now.ToLongTimeString();
objCMD.Parameters["@.Create_DateTime"].Direction = ParameterDirection.Input;

objCMD.Parameters.Add("@.Image_FileName", SqlDbType.NVarChar, 50);
objCMD.Parameters["@.Image_FileName"].Value = imgName;
objCMD.Parameters["@.Image_FileName"].Direction = ParameterDirection.Input;
objCMD.Parameters.Add("@.Image_ContentType", SqlDbType.NVarChar, 50);
objCMD.Parameters["@.Image_ContentType"].Value = imgcontenttype;
objCMD.Parameters["@.Image_ContentType"].Direction = ParameterDirection.Input;

objCMD.Parameters.Add("@.Image_ImageData", SqlDbType.Image);
objCMD.Parameters["@.Image_ImageData"].Value = imgbin;
objCMD.Parameters["@.Image_ImageData"].Direction = ParameterDirection.Input;

int numRowsAffected = objCMD.ExecuteNonQuery();
return numRowsAffected;

}Are you saying you don't get an exception and there row isn't inserted? BTW Don't prefix your procs with "sp_" its bad for perf' they're really reserved for "system procedure".