Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

image into sql database

protected void btnUpload_Click(object sender, EventArgs e)
{
 string strImageName = txtName.Text.ToString();
 if (FileUpload1.PostedFile != null && 
     FileUpload1.PostedFile.FileName != "")
  {
   byte[] imageSize = new byte
                 [FileUpload1.PostedFile.ContentLength];
  HttpPostedFile uploadedImage = FileUpload1.PostedFile;
  uploadedImage.InputStream.Read
     (imageSize, 0, (int)FileUpload1.PostedFile.ContentLength);
 
 // Create SQL Connection 
  SqlConnection con = new SqlConnection();
  con.ConnectionString = ConfigurationManager.ConnectionStrings
                         ["ConnectionString"].ConnectionString;
 
 // Create SQL Command 
 
 SqlCommand cmd = new SqlCommand();
 cmd.CommandText = "INSERT INTO Images(ImageName,Image)" +
                   " VALUES (@ImageName,@Image)";
 cmd.CommandType = CommandType.Text;
 cmd.Connection = con;
 
 SqlParameter ImageName = new SqlParameter
                     ("@ImageName", SqlDbType.VarChar, 50);
 ImageName.Value = strImageName.ToString();
 cmd.Parameters.Add(ImageName);
 
 SqlParameter UploadedImage = new SqlParameter
               ("@Image", SqlDbType.Image, imageSize.Length);
 UploadedImage.Value = imageSize;
 cmd.Parameters.Add(UploadedImage);
 con.Open();
 int result = cmd.ExecuteNonQuery();
 con.Close();
 if (result > 0)
 lblMessage.Text = "File Uploaded";
 GridView1.DataBind();
 }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: rename join table in many to many 
Csharp :: c# task call more web api in parallel 
Csharp :: Custom Circular Picture Box C# win Form app 
Csharp :: c# use meditor from service 
Csharp :: c# read csv file save to database dynamically 
Csharp :: csharp test for null 
Csharp :: generate random light color android 
Csharp :: c# if loop 
Csharp :: c# timestamp 
Csharp :: unity disable the display of the camera frustrum 
Csharp :: telerik mvc grid editable date no time 
Csharp :: return a list of list from yaml via C# 
Csharp :: Unity FPS camera z axis rotating problem 
Csharp :: system.text.json ways to go about getting to the data how to get the data text.json you should use JsonDocument when 
Csharp :: when creating a new boolean column in an existing table how to set the default value as true in c# models code first 
Csharp :: c# ef dynamic ApplyConfiguration 
Csharp :: c# gridview summary item displayformat 
Csharp :: how to integrate a c# and angular 9 
Csharp :: startup c# class winform 
Csharp :: anidate bucle in c# 
Csharp :: get current culture in controller asp.net core 
Csharp :: c# expression func automatically select return type 
Csharp :: file.deletealltext 
Csharp :: unity on statement how 
Csharp :: version string c# 
Csharp :: uity pause game 
Csharp :: c# aspx return image 
Csharp :: Difference between UnitOfWork and Repository Pattern 
Csharp :: wpf settings core 
Csharp :: start wpf application when windows start 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =