Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Upload fajla u SQL tabelu pomocu C#

[es] :: .NET :: .NET Desktop razvoj :: Upload fajla u SQL tabelu pomocu C#

[ Pregleda: 2644 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Ognjen_NS
NoviSad

Član broj: 76177
Poruke: 82
*.panline.net.



Profil

icon Upload fajla u SQL tabelu pomocu C#23.12.2005. u 21:38 - pre 223 meseci
Jel zna neko mozda kojeg tipa treba biti polje u SQL tabeli, i kako pomocu C# da korisnik upload-uje fajl
HVALA
 
Odgovor na temu

dusans
Stojanov Dušan
Pančevo

Član broj: 9551
Poruke: 1343
*.3dnet.co.yu.



+311 Profil

icon Re: Upload fajla u SQL tabelu pomocu C#24.12.2005. u 08:50 - pre 223 meseci
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()
 
Odgovor na temu

[es] :: .NET :: .NET Desktop razvoj :: Upload fajla u SQL tabelu pomocu C#

[ Pregleda: 2644 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.