求救!asp.net+c#上传图片到access数据库及显示图片的代码?

unexpectedly 2003-11-17 12:10:18
不要VB.net和带SQL Server存储过程的方法,用不上哦!
...全文
91 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xhzuo 2003-11-18
  • 打赏
  • 举报
回复
你把存储过程中的sql语句提取出来,不就能用了吗
unexpectedly 2003-11-18
  • 打赏
  • 举报
回复
多谢楼上两位兄弟,上传图片有没有不带存储过程的?你们的都带啊?
elite2018 2003-11-17
  • 打赏
  • 举报
回复
show it :

private void Page_Load(object sender, System.EventArgs e)

{

string imgid =Request.QueryString["imgid"];

string connstr=((NameValueCollection)

Context.GetConfig("appSettings"))["connstr"];

string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = "

+ imgid;

SqlConnection connection = new SqlConnection(connstr);

SqlCommand command = new SqlCommand(sql, connection);

connection.Open();

SqlDataReader dr = command.ExecuteReader();

if(dr.Read())

{

Response.ContentType = dr["imgtype"].ToString();

Response.BinaryWrite( (byte[]) dr["imgdata"] );

}

connection.Close();

}

elite2018 2003-11-17
  • 打赏
  • 举报
回复
store it :


Stream imgdatastream = File1.PostedFile.InputStream;

int imgdatalen = File1.PostedFile.ContentLength;

string imgtype = File1.PostedFile.ContentType;

string imgtitle = TextBox1.Text;

byte[] imgdata = new byte[imgdatalen];

int n = imgdatastream.Read(imgdata,0,imgdatalen);

string connstr=

((NameValueCollection)Context.GetConfig

("appSettings"))["connstr"];

SqlConnection connection = new SqlConnection(connstr);

SqlCommand command = new SqlCommand

("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)

VALUES ( @imgtitle, @imgtype,@imgdata )", connection );



SqlParameter paramTitle = new SqlParameter

("@imgtitle", SqlDbType.VarChar,50 );

paramTitle.Value = imgtitle;

command.Parameters.Add( paramTitle);



SqlParameter paramData = new SqlParameter

( "@imgdata", SqlDbType.Image );

paramData.Value = imgdata;

command.Parameters.Add( paramData );



SqlParameter paramType = new SqlParameter

( "@imgtype", SqlDbType.VarChar,50 );

paramType.Value = imgtype;

command.Parameters.Add( paramType );



connection.Open();

int numRowsAffected = command.ExecuteNonQuery();

connection.Close();
sjc0 2003-11-17
  • 打赏
  • 举报
回复
我用了存储过程不过你改改
Stream stream = insertimg.PostedFile.InputStream;
byte[] buffer = new byte[insertimg.PostedFile.ContentLength];
int aa = stream.Read(buffer, 0, (int)stream.Length);
string filename = System.IO.Path.GetFileNameWithoutExtension(insertimg.PostedFile.FileName.ToString());
string expandname = Path.GetExtension(insertimg.PostedFile.FileName.ToString());
int size = (int)stream.Length;
stream.Read(buffer, 0, size);
你把buffer传入你的image字段就可以了!
unexpectedly 2003-11-17
  • 打赏
  • 举报
回复
U P

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧