Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Storing an image path

Author  Topic 

arganum
Starting Member

4 Posts

Posted - 2009-07-01 : 16:12:34
What I have been working is an application that will allow the user to upload an image to a web server. I used asp:FileUpload control to do this. Anyway, what I need to do now is save, at the same time as the upload, the path to that image in SQL. How do I go about doing this? Is there an example that I can look at?

Thank you for any help that you can give me

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-01 : 16:18:22
INSERT INTO imageTable(id, FilePath) SELECT @id, @FilePath

???

I'm sure you mean something else though



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

arganum
Starting Member

4 Posts

Posted - 2009-07-01 : 16:25:58
With that INSERT INTO statement, what FilePath will be saved?
What I need is the path to the image in the server with my hosting company. I am sorry that I am not good at explaining this out. My newbieness is showing I'm afraid.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-01 : 16:29:29
what ever filepath YOU supply?

Are you asking this as a development platform question?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

arganum
Starting Member

4 Posts

Posted - 2009-07-01 : 16:46:57
The name of the folder where the images are being saved is watercolorImages.
So that path would need to be:
watercolorImages/'whatever the image name is'
How can I grab that name and add it to the path as it is being saved?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-01 : 16:52:28
you're giving us precious little to go on ya know

what are you working in?

If it's not sql server, then you are going to have some difficulty finding an answer on a sql server tech site



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

arganum
Starting Member

4 Posts

Posted - 2009-07-01 : 16:57:09
I am working in Visual Studio 2008 with C#. I am using SQL Express 2008 as well.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-01 : 17:00:22
So you want to know how to get the path name in c#?????



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-07-01 : 17:02:45
It's a long way to the top if you wanna yak'n'roll


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-02 : 07:38:24
Am not sure ... what u expect...try

private void cmdSave_Click(object sender, EventArgs e){ try { //Read Image Bytes into a byte array byte[] imageData = ReadFile(txtImagePath.Text); //Initialize SQL Server Connection SqlConnection CN = new SqlConnection(txtConnectionString.Text); //Set insert query string qry = "insert into ImagesStore (OriginalPath,ImageData) _ values(@OriginalPath, @ImageData)"; //Initialize SqlCommand object for insert. SqlCommand SqlCom = new SqlCommand(qry, CN); //We are passing Original Image Path and //Image byte data as sql parameters. SqlCom.Parameters.Add(new SqlParameter("@OriginalPath", (object)txtImagePath.Text)); SqlCom.Parameters.Add(new SqlParameter("@ImageData", (object)imageData)); //Open connection and execute insert query. CN.Open(); SqlCom.ExecuteNonQuery(); CN.Close(); //Close form and return to list or images. this.Close(); }
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-07-02 : 07:39:30
Hi arganum

To store an image in to sql server, you need to read image file into a byte array. Once you have image data in byte array, you can easity store this image data in sql server using sql parameters

Go to Top of Page
   

- Advertisement -