Wednesday, January 6, 2010

Upload Image to database in Binary formate

This is a sample code for uploading images in database.


protected void Button1_Click(object sender, EventArgs e)
{
byte[] image = FileUpload1.FileBytes;

String name = TextBox1.Text;

String qryString = "INSERT INTO [Table] VALUES ( '" + name + "' , '" + image + "' )";
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(qryString, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}
}


for more details download code from here

No comments: