Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MyClass obj = new MyClass();
- obj.Name = Request["name"]; // other properties
- obj.Alt = Request["altText"];
- HttpPostedFile file = Request.Files[0];
- if (file != null)
- {
- obj.Image image = new byte[file.ContentLength];
- file.Read(obj.Image,0,file.ContentLength];
- }
- using (DataContext context = new DataContext())
- {
- context.InsertOnSubmit( obj );
- context.SubmitChanges();
- }
- String b64;
- using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
- {
- this.pic.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
- Byte[] bytes = ms.ToArray();
- b64 = Convert.ToBase64String(bytes);
- }
- using (SqlConnection conn = new SqlConnection(ConnectionString))
- {
- using (SqlCommand cmd = new SqlCommand("UPDATE [settings] SET [value] = @val WHERE [id] = 2", conn))
- {
- conn.Open();
- cmd.Parameters.Add(new SqlParameter("@val", b64));
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- }
- SqlConnection conn = new SqlConnection("<your connection string>");
- conn.Open();
- SqlCommand cmd = new SqlCommand("TestProc", conn);
- cmd.CommandType = CommandType.StoredProcedure;
- SqlParameter param = new SqlParameter("@data", SqlDbType.Image);
- param.Value = System.IO.File.ReadAllBytes("any_file.jpg");
- cmd.Parameters.Add(param);
- cmd.ExecuteNonQuery();
Add Comment
Please, Sign In to add comment