1,
System.Web.UI.WebControls.FileUpload fupload_teacher_image;
在页面上声音上述控件
2,
在某按钮的事件下(.CS文件中)声音一个BYTE数组
byte[] bDefaultPhoto = fupload_teacher_image.FileBytes;
3.
声明SQL语句
string sql = "UPDATE TeacherClientConfig SET DefaultPhoto = @DefaultPhoto";
其中,DefaultPhoto的类型为IMAGE类型
4.
//构造参数
SqlParameter[] sqlParameter = {
new SqlParameter("@DefaultPhoto",SqlDbType.Image),
};
//为参数传值
int i = 0;
sqlParameter[i++].Value = bDefault;
5.
上传至数据库,因为DB层的写法谁跟谁的都不太一样,代码仅供参考
SqlCommand Command = new SqlCommand();
Command.Connection = Conn;
Command.Transaction = Trans;
Command.CommandText = SqlText;
Command.CommandType = CommandType.Text;
// 加入参数列表
if (Params != null)
{
for (int i = 0; i < Params.Length; i++)
Command.Parameters.Add(Params[i]);
}
nRet = Command.ExecuteNonQuery();
需要注意的地方,
new SqlParameter("@DefaultPhoto",SqlDbType.Image),
注意参数类型为SqlDbType.Image
6.
如何显示呢?跟普通的查询一样,首先查询出来这一列
const string SqlString = "SELECT WelcomePic FROM TeacherClientConfig";
7.
新建一个"一般性文件",扩展名为ASHX
打开它,写下类似下面的代码,测试吧!~
///
/// $codebehindclassname$ 的摘要说明
/// [WebService(Namespace = "
http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class RenderImageWelcome : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/gif";
byte[] bDefaultPhoto = ACPublic.PubDbOperator.SelectConfigImageForWelcome();
if (bDefaultPhoto != null && bDefaultPhoto.Length > 0)
{
context.Response.Clear();
context.Response.Buffer = true;
context.Response.OutputStream.Write(bDefaultPhoto, 0, bDefaultPhoto.Length);
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}