How to add BLOB column in database?

2k views Asked by At

I have read that for saving images into my database I need a datatype called BLOB. Also, in this link Microsoft Access Data Types, that for adding a column BLOB in my database working in Microsoft Access I need Ole Object. So I have done some tries like this one:

public partial class alterOneSec : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OleDbConnection con = DAL.GetConnection();
        con.Open();
        if(con.State == ConnectionState.Open)
        {
            string sql = "ALTER TABLE item ADD picture OLE";
            OleDbCommand cmd = DAL.GetCommand(con, sql);
            int num = cmd.ExecuteNonQuery();
            if(num == 0)
            {
                Response.Redirect("homepage.aspx?err=error");
            }
        }
        con.Close();
        Response.Redirect("homepage.aspx?err=case3");
    }
}

I want to add a column picture to my database in the table item where I can save pictures that people attach for example. I tried also string sql = "ALTER TABLE item ADD picture OLE OBJECT and string sql = "ALTER TABLE item ADD picture BLOB"all this three cases throw an exception:

An exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll but was not handled in user code. Additional information: Syntax error in field definition.

How do I add this column for pictures? Thanks!

1

There are 1 answers

0
Hugh On BEST ANSWER

Try using

ALTER TABLE item ADD picture LONGBINARY