[ Ognjen_NS @ 23.12.2005. 21:38 ] @
Jel zna neko mozda kojeg tipa treba biti polje u SQL tabeli, i kako pomocu C# da korisnik upload-uje fajl HVALA |
[ Ognjen_NS @ 23.12.2005. 21:38 ] @
[ dusans @ 24.12.2005. 08:50 ] @
Polje treba biti tipa Image. Kod ide otprilike ovako:
Code: string FileName; string ConnectionString; System.Data.SqlClient.SqlConnection Connection; System.Data.SqlClient.SqlCommand Command; System.IO.Stream FileStream; // Set the file name and connection string FileName = "C:\\Temp\\Test.doc"; ConnectionString = "data source=.;initial catalog=Test;persist security info=False;user id=sa;password=;packet size=4096;Connect Timeout=240"; // Open file stream FileStream = System.IO.File.OpenRead(FileName); byte[] FileContents=new byte[FileStream.Length - 1]; // Read contents of file into Byte array FileStream.Read(FileContents, 0, (int)FileStream.Length); // Close file stream FileStream.Close(); // Create connection to database Connection = new System.Data.SqlClient.SqlConnection (ConnectionString); // Create insert command Command = new System.Data.SqlClient.SqlCommand("INSERT INTO Test(FileContents) VALUES (@FILECONTENTS)", Connection); Command.Parameters.Add (new System.Data.SqlClient.SqlParameter("@FILECONTENTS", FileContents)); // Open connection Connection.Open(); // Perform update Command.ExecuteNonQuery(); // Close connection Connection.Close() Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.
|