Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want to Saving Multiple Image Path url in Database at once.
Posted
Comments
Zoltán Zörgő 1-Mar-15 9:46am    
Good for you. Go for it!
Aarti Yadav 1-Mar-15 9:49am    
what ... can u give me suggestion how to do it.... i can just store one path not all
Zoltán Zörgő 1-Mar-15 9:55am    
Why not?
You have at least two possibilities depending on the usage of the database:
1) Normalized approach: add a new table for the URLs and add a foreign key reference to your current table. Just add the URLs in an 1:N relation.
2) Not normalized approach: use an nvarchar(MAX) field and put them all in a single field separated by whatever you like.
(and several more)
At the end your upper layer has to deal with it.

1 solution

You can set a loop to store the names of the files in the SQL database. For example, if the images come from a request, you would possibly write this code.

C#
foreach (var file in Request.Files) {
   // now get the name of each file
   var filename = file.FileName;
   // execute the following command, 
   var command = "INSERT INTO table_name (FileName) VALUES (@0)";
   // 0 is a parameter, update it. 
}


I have not written any code for the execution, because it depends on whether you're using the Database object of WebMatrix.Data or you're using the SqlClient object.

Edit

Since you're using SqlClient, you can use the SqlCommand[^] and execute it. The result would be the number of rows affected (created in the case of INSERT INTO).
 
Share this answer
 
v2
Comments
Aarti Yadav 1-Mar-15 10:03am    
i am using sqlclient
Afzaal Ahmad Zeeshan 1-Mar-15 10:12am    
Please see the update in my answer.
Aarti Yadav 1-Mar-15 10:06am    
can u tell me a whole code...
Afzaal Ahmad Zeeshan 1-Mar-15 10:13am    
No - you have to do at least the minimum programming. We help you if you get into trouble while coding, not starting coding, sorry Aarti.
Aarti Yadav 1-Mar-15 10:17am    
nah its oky my mistek, i have to do however.. :( sorry .... i m going to try .. Thnx For d solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900