Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 1 odgovor
  • 3.135 pregleda

Najnovija ↓

Upload fajla u SQL tabelu pomocu C# 23.12.2005. u 22:38 · pre 253 meseca #1
Jel zna neko mozda kojeg tipa treba biti polje u SQL tabeli, i kako pomocu C# da korisnik upload-uje fajl
HVALA
Re: Upload fajla u SQL tabelu pomocu C# 24.12.2005. u 09:50 · pre 253 meseca #2
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()
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme