如何在数据库中添加BLOB列?

时间:2015-06-26 18:49:12

标签: c# image blob oledbcommand oledbexception

我已经读过用于将图像保存到我的数据库中我需要一种名为 BLOB 的数据类型。另外,在此链接Microsoft Access Data Types中,为了在Microsoft Access中使用我的数据库中添加列BLOB,我需要 Ole Object 。所以我做了一些像这样的尝试:

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");
    }
}

我想在项目表格中向我的数据库添加图片列,例如我可以保存人们附加的图片。我还尝试了string sql = "ALTER TABLE item ADD picture OLE OBJECTstring sql = "ALTER TABLE item ADD picture BLOB"所有这三种情况都会引发异常:

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.

如何为图片添加此列? 谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用

ALTER TABLE item ADD picture LONGBINARY