使用asp.net中的两个上载控件将两个文件上载到sql [英] uploading two files using two upload controls in asp.net to sql

查看:100
本文介绍了使用asp.net中的两个上载控件将两个文件上载到sql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件上传控件和一个按钮


文件上传一个,用于上传一张图片


文件上传,用于上传另一张图片

当我单击提交..我需要将两个图像都存储在sql中...



然后我需要使用图像控件将图像检索回表格....

如果可能的话,请帮助我亲爱的朋友...

I have two file upload controls and a button


file upload one used to upload one image


file upload one used to upload another image

when i click submit .. i need to store both images in sql...



Then i need to retrieve image back to form using image control ....

Help me if possible dear friends...

推荐答案

这是一项简单的任务,与您的上传控件无关(它只是存储图像在SQL中),并在网络上广泛记录.你尝试了什么?为什么要存储图像而不是图像文件的路径.这确实意味着您需要编写一个页面,该页面返回基于id的图像字节,这是基于Web的任务,您需要执行该任务才能使其以这种方式工作.

值得一提的是,自12月24日以来,您一直在询问这个问题的变体.您是否真的还没有找到解决方案?你一直在做什么?
This is an easy task, which has nothing to do with your upload controls ( it''s just storing an image in SQL ) and is widely documented on the web. What have you tried ? Why do you want to store the images and not the paths to image files. This DOES mean you''ll need to write a page which returns the image bytes based on an id, that IS a web based task you''ll need to perform to make it work this way.

It''s worth mentioning that you''ve been asking variations of this question since Dec 24. Are you still really no closer to a solution ? What have you been doing all this time ?


使用单个文件上传我明白了..添加多个文件,我需要yar ...
using single file upload i got it.. to add multiple files i need yar...
protected void Button1_Click(object sender, EventArgs e)
   {
       int imagelen = FileUpload1.PostedFile.ContentLength;
       byte[] picbyte = new byte[imagelen];
       FileUpload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);
       //Upload1.PostedFile.InputStream.Read(picbyte, 0, imagelen);

       SqlConnection conn = new SqlConnection("server=SRM02;database=image;integrated security=true");
       try
       {
           conn.Open();
           SqlCommand cmd = new SqlCommand("insert into Imagetable" +" (Image1,id) " +" values (@pic, @imageid)",conn);
           cmd.Parameters.Add("pic", picbyte);
           cmd.Parameters.Add("@imageid", TextBox1.Text);

           cmd.ExecuteNonQuery();
       }
       finally
       {
           conn.Close();
       }
   }


我不确定为什么您仍在添加假答案而不是编辑帖子.好的,所以您的问题根本不是您提出的问题.我完全看不到你有什么问题.您有两个上传控件.您有适用于一个的代码.为什么不能将代码同时应用于两者?您的特定问题是什么?上传两个文件是否可行?如果不是那样,如果您一次上传的代码工作正常,我将茫然地看到您怎么可能遇到问题.
I''m not sure why you''re still adding fake answers instead of editing your post. OK, so your question is not remotely what you asked at all. I don''t see how you have a question at all. You have two upload controls. You have code that works for one. Why can''t you apply your code to both ? What is your SPECIFIC problem ? Is it working out if two files were uploaded ? If not that, I am at a loss to see how you could have an issue if your code for one upload works fine.


这篇关于使用asp.net中的两个上载控件将两个文件上载到sql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆