if you need to insert new record; use
insert SQL statement[
^]
if you need to update existing record;
use update SQL statement[
^]
below is sample code which insert image data to access database using
OleDbConnection
protected void btnSaveImage_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string name = FileUpload1.PostedFile.FileName;
int length = FileUpload1.PostedFile.ContentLength;
byte[] imageBytes = new byte[length];
Stream imageStream = FileUpload1.PostedFile.InputStream;
imageStream.Read(imageBytes, 0, length);
string connString = ConfigurationManager.ConnectionStrings["ImagesDB"].ConnectionString;
OleDbConnection connection = new OleDbConnection(connString);
string insertQuery = "INSERT INTO Images(ImageName, ImageSize, ImageData) VALUES(@ImageName, @ImageSize, @ImageData)";
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = insertQuery;
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@ImageName", name);
command.Parameters.AddWithValue("@ImageSize", length);
command.Parameters.AddWithValue("@ImageData", imageBytes);
try
{
connection.Open();
command.ExecuteNonQuery();
lblMessage.Text = "Image data saved successfully";
}
catch (Exception ex)
{
lblMessage.Text = "Unable to save image data";
}
finally
{
connection.Close();
}
}
}
Refer this
article [
^]