answersLogoWhite

0

We can store images as well as files in database. Use this code for Onclick event of upload button :-

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();

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What is queries in data base?

query is a request for retrive the information from the database.


How do you retrive a value from combo box whose values are retrived from database?

ii


Rename iPhone photo albums?

There is no simple way to rename iPhone photo albums because all photos in iPhone photo albums stored as binary format ITHMDB photo database, there are 5 type of database as below 1. "Photo Database" stored photo index to the other 4 databases. 2. "F3008_1.ITHMB" stored image size 640 x 480 3. "F3009_1.ITHMB" stored image size 160 x 128 4. "F3004_1.ITHMB" stored image size 56 x 73 5. "F3011_1.ITHMB" stored image size 80 x 79 Mac platform: I guess iPhoto can do the job. Windows platform: "uTunePhotos" that can manipulate ITHMDB database can do the job such as add, remove, export rename, reorder, backup and restore.


What is active database and cloud database?

The database we use in our daily life is called as active database . The data that is stored in the database which is further stored on the cloud is called cloud database.


Difference between flat file and database file?

DATABASE FILE - is one that is stored on a server and it is in the format that the database needs to read it. It is stored in the database catalog......


What order are files stored in the database?

simply files are stored in database in upper to lower order.


Where is a database stored?

ram


Hos is DBMS different from a Database?

DBMS is database management. Database is where the information is stored.


Are Highly structured and organized data is stored in database files?

are structured and organized data stored in database files


Data base state vs database schema?

The database schema is the description of the database. It defines how the database is set up and what data it is to contain and control. This description is given to the DBMS to manage the data. The database state is an image of how the database looks at any given time. The database schema is set unless you change how the database is structured. The database state will change whenever new data is entered into the database and the database is updated.


What is the difference between database and database administrator?

Database is the data stored in the server and Database administrator is the person who designs the database.


Enter on the database or in the database?

We would use in rather than on. Data is stored in a database, not on a database. Data is entered into a database not onto a database.