【发布时间】: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 OBJECT和string 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.
如何为图片添加此列? 谢谢!
【问题讨论】:
-
使用 LONGBINARY,如下所述:stackoverflow.com/questions/3002026/…
标签: c# image blob oledbcommand oledbexception