二进制图片封装成类 现在的需求 将图片以二进制的方式存入或者读取 数据库中 如果在一个页面里 我可以写出来 也实现出来过 但我想将这个方法封装起来 方便调用 还请大侠帮帮忙一个是存入数据库的 一个是从数据库中读取的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不能直接用byte[]? 不需要定义成类吧? 读取的 string sql = string.Empty; SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=findFriend"); con.Open(); sql="......"; SqlCommand cmd = new SqlCommand(sql, con); SqlDataReader sdr = cmd.ExecuteReader(); byte[] buffer = null; while (sdr.Read()) { buffer = (byte[])sdr["image"]; Response.ContentType = "application/octet-stream"; Response.BinaryWrite(buffer); } con.Close(); sdr.Close(); Response.End();插入的 //二进制数组 byte[] buffer = new byte[size]; Stream picstream = FileUpload1.PostedFile.InputStream; picstream.Read(buffer, 0, size); string sql = string.Empty; SqlCommand cmd; int iRet = 0; UserInfo ui = (UserInfo)Session["user"]; SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123;database=findFriend"); conn.Open(); sql = string.Format("select COUNT(*) from photo where UId={0} and head=1", ui.id); cmd = new SqlCommand(sql, conn); int i = Convert.ToInt32(cmd.ExecuteScalar()); if (i > 0) { sql = string.Format("update photo set size='{0}',type='{1}',name='{2}',image=@image where UId='{3}'", size, type, name,ui.id); cmd = new SqlCommand(sql, conn); cmd.Parameters.Add("@image", SqlDbType.Image); cmd.Parameters["@image"].Value = buffer; iRet = cmd.ExecuteNonQuery(); Panel1.Visible = true; Panel2.Visible = false; } 发个小贴问问高手先。关于后台身管理身份的。 初学ASP.NET就被困住, SqlDataAdapter.Fill()比高效的存储过程效率还高,郁闷中??(请高手指点) DataGrid小问题希望大家帮忙解决. WebCombo控件如何指定某行被选中 急:自定义的控件.ascx可以在网页中动态生成吗? 为什么TreeView控件没有Mouse事件 这是什么意思``C#的 关于html上传控件的问题 RowSelectionModel 能不能通行事件返回所选记录的多个数值? 用cheditor替换textbox后获取值 .NET 页面控件后台无法识别
string sql = string.Empty;
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=findFriend");
con.Open();
sql="......";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataReader sdr = cmd.ExecuteReader();
byte[] buffer = null;
while (sdr.Read())
{
buffer = (byte[])sdr["image"];
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(buffer); }
con.Close();
sdr.Close();
Response.End();插入的 //二进制数组
byte[] buffer = new byte[size];
Stream picstream = FileUpload1.PostedFile.InputStream;
picstream.Read(buffer, 0, size);
string sql = string.Empty;
SqlCommand cmd;
int iRet = 0;
UserInfo ui = (UserInfo)Session["user"];
SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=123;database=findFriend");
conn.Open();
sql = string.Format("select COUNT(*) from photo where UId={0} and head=1", ui.id);
cmd = new SqlCommand(sql, conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
{
sql = string.Format("update photo set size='{0}',type='{1}',name='{2}',image=@image where UId='{3}'",
size, type, name,ui.id); cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@image", SqlDbType.Image);
cmd.Parameters["@image"].Value = buffer;
iRet = cmd.ExecuteNonQuery();
Panel1.Visible = true;
Panel2.Visible = false;
}