Wednesday, December 7, 2011

Writing BLOG Data to the Database

Writing BLOG Data to the Database
public void  StorePicture( string filename )
   // Read the file into a byte array
   using(FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
     byte[] imageData = new Byte[fs.Length];
     fs.Read( imageData, 0, (int)fs.Length );
   using( SqlConnection conn = new SqlConnection(connectionString) )
     SqlCommand cmd = new SqlCommand("StorePicture", conn);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@filename", filename );
     cmd.Parameters["@filename"].Direction = ParameterDirection.Input;
     cmd.Parameters.Add("@blobdata", SqlDbType.Image);
     cmd.Parameters["@blobdata"].Direction = ParameterDirection.Input;
     // Store the byte array within the image field
     cmd.Parameters["@blobdata"].Value = imageData;

Action Method in Mvc

In this section, you will learn about the action method of controller class. All the public methods of a Controller class are called Act...