This is my first time really dealing with C# i did this in VB with ASP but never with C#.

What i need to do is take data that I enter into a textbox and save it to my SQL server and there is also a Image that needs to save to it also.

Thanks for the help.

Recommended Answers

All 3 Replies

Hi,
You can find plenty of code snippets on MSDN to help you with that. Here's one answer:
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/91bd10ce-c83b-4766-920b-2137ddc29908

As for saving the image, there are two things you can do; save the name (and possibly file location if it isn't consistent) of the image to the database and save the image to a folder (always my preferred option) or save the image into the database as a blob data type.

Hope that helps,

Thanks that helped. Got all working now.

Only thing can't find is how to use the fileupload in ASP.Net so i browse to find an image and the save it to database.

If you can help thanks.

That's easy. You can do something like this:

For example, if you want to store an image to a folder called "images" in the root of your site and the file upload control is called "fuImage".

if (fuImage.HasFile) //in here you can make multiple checks, like content type, etc
    {
      string path = Server.MapPath("images"); //this will get the physical path to the images folder
      fuImage.SaveAs(path + fuImage.PostedFile.FileName); // the fuImage.PostedFile.FileName is the original name of your uploaded file, you can always change it (and imo I recomend you to do it).
    }

This an very very simple example. IMO you should always check if a file with the same name exists and delete it or rename the new one.

Hope that this would help you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.