(高分求助:)c#.net中,怎么实现将图片保存到数据库中?
c#.net中,怎么实现将图片保存到数据库中?
用picturebox控件,双击后把图片保存到数据库中,然后再显示!!
[解决办法]
http://www.cnblogs.com/jhtchina/articles/178129.html
[解决办法]
/// <summary>
/// File -> DB
/// </summary>
/// <param name= "file "> </param>
/// <returns> </returns>
public static bool File2DB(string file)
{
try
{
// 文件名 -> byte[]
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, (int)fs.Length);
fs.Close();
SqlConnection db = new SqlConnection(strConn);
string strSQL = "INSERT INTO t_FileBase (FileData,....) values (@data....) ";
SqlCommand cmd = new SqlCommand(strSQL, db);
cmd.Parameters.Add( "@data ", SqlDbType.Image, data.Length);
cmd.Parameters[ "@data "].Value = data;
db.Open();
cmd.ExecuteNonQuery();
// 释放资源
....
return true;
}
catch(SqlException sqlex)
{
//Prompt(sqlex.Message);
return false;
}
}