Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created January 19, 2011 17:44
Show Gist options
  • Save efleming969/786528 to your computer and use it in GitHub Desktop.
Save efleming969/786528 to your computer and use it in GitHub Desktop.
protected void Button4_Click(object sender, EventArgs e) {
string strImageName = txtName.Text.ToString();
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") {
byte[] imageBytes = new byte[FileToUpload.PostedFile.InputStream.Length + 1];
FileToUpload.PostedFile.InputStream.Read(imageBytes, 0, imageBytes.Length);
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["FileUpload"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into Image (ImageData) Values (@Image)";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@Image", imageBytes);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment