【问题标题】:How to add BLOB column in database?如何在数据库中添加 BLOB 列?
【发布时间】:2015-09-13 19:43:12
【问题描述】:

我已阅读为了将图像保存到我的数据库中,我需要一个名为 BLOB 的数据类型。此外,在此链接Microsoft Access Data Types 中,要在我的数据库中添加一个在 Microsoft Access 中工作的列 BLOB,我需要 Ole 对象。所以我做了一些这样的尝试:

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

我想在我的数据库中的 item 表中添加一列 picture,例如,我可以在其中保存人们附加的图片。我也试过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.

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

【问题讨论】:

标签: c# image blob oledbcommand oledbexception


【解决方案1】:

尝试使用

ALTER TABLE item ADD picture LONGBINARY

【讨论】:

    猜你喜欢
    • 2022-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 1970-01-01
    • 2019-01-20
    • 1970-01-01
    • 2013-08-20
    相关资源
    最近更新 更多