本站首页
|
代码实验室
|
CSS3 中文参考
|
书籍出版
|
Google 英文翻译版
|
给我留言
文章标题
文章内容
.NET 相关
ASP.NET
ASP.NET MVC
Sliverlight
Linq
C#
F#
VB.NET
Web Services
XML/XSL
.NET FAQ
Web 开发
Internet Explorer
CSS
Javascript
SQL Server
Java应用
友情链接
关于 ASP.NET2.0中将文件上传到数据库 的评论:
评论日期:2007年06月04日 00:00:00
评论人:爪子嘛
说实话
对于一个搞vb。net的初级学习者而言我看得很吃了
我要吃饭
评论日期:2007年05月06日 00:00:00
评论人:maoliy
急求用C#的多文件多类型本地上传SQL数据库,然后从SQL数据库下载到本地的代码,谢谢
评论日期:2007年05月15日 00:00:00
评论人:easygoer
如果是 传附件,并显示 可打开并下载的,怎么写啊.
附件文件内容存在一个字段里应该放不下吧,怎么处理呢.
评论日期:2007年10月11日 00:00:00
评论人:shijie00
这代码写的太仗了
我能拜在你的门下吗?
我的邮箱是loveshijie.ok@gmail.com
或者你把你的联系方式告诉我
我遇到困难可以找你帮忙吗?
很是佩服你!希望你能够收留我啊
评论日期:2007年07月26日 00:00:00
评论人:whs2893
显示GridView时,查询了一次表UserPhoto;显示图片时,又查询了一次表UserPhoto。查询两次不太好。
因为在显示GridView时,字段ContentType和Photo的值已经知道,不知是否有方法不调用ReadImage.aspx这个页面就可以显示?
评论日期:2007年08月02日 00:00:00
评论人:doudou
请问:我要把客户端A数据库的内容提取出来写入到客户端B数据库中,那么作为服务器上的应用程序我该用什么技术实现?
谢谢各位了.
评论日期:2007年08月07日 00:00:00
评论人:lihz
这样放在数据库好慢啊,这样做有什么好处吗?
评论日期:2007年10月23日 00:00:00
评论人:suisuichao
呵呵,不错,试了一下,sql server的,可以哦,多谢啦
评论日期:2007年11月09日 00:00:00
评论人:suyiming
好像这个不是很难啊 我刚上手的就做了这个 不过都是获取图片 限制图片大小 等比例显示有点麻烦
评论日期:2007年11月29日 00:00:00
评论人:weblogical
我在站点文件夹下上传了新的aspx文件,同时上传了对应的dll,但是为什么无法访问呢?很奇怪,这个文件夹下面其它aspx文件倒是可以访问
评论日期:2007年12月12日 00:00:00
评论人:melaker
孟老师,你好,我是小孟,叫孟凡华,我想问下用asp.net开发前台和后台的代码,实现多文件多类型的截图及上传功能。客户机一上传,要求服务器中有提示在线显示功能,能给帮忙写写代码么,谢谢了。
评论日期:2007年12月27日 00:00:00
评论人:NiaoRen
真的很不错 我是在我们教科书上的推荐网站上看到这个网站上的 简直就是太牛了你
评论日期:2007年12月28日 00:00:00
评论人:molly
请教个问题,我把公司的网站弄坏了,本来是想修一下每一页下面的电话号码(不知道怎样通过模板改就一页页弄的),可七改八改的,传上去覆盖后发现图片都没了,人家告诉把图片放在images里,可是我弄回去了还是不成!现在真是要哭死了,我是菜鸟,很菜很菜的那种,请哪位高手指点啊,感激不尽!!
评论日期:2008年01月03日 00:00:00
评论人:zhiyewang
请教个问题:NET如何获取URL中带有#等特殊字符的参数。
评论日期:2008年01月03日 00:00:00
评论人:NiaoRen
今天在做個小項目時碰到了點小問題 上來看了一下您寫的代碼 突然明白了 真的是很感謝您
以前大一的時候貪玩 現在聽老師講課很吃力 您在這里給了我一個自學的途徑
评论日期:2008年01月12日 00:00:00
评论人:ss
<script type="text/javascript"></script>
评论日期:2008年01月20日 00:00:00
评论人:21ytnet.com
看了这些,使我得了点启发,谢谢
评论日期:2008年01月28日 00:00:00
评论人:pillar_BD
只不过是.net平台的小项目,小把戏而已不必太佩服了 我是Java方向的 可是对于<.net>虽不说精通但敢说略知一二!!
我很善于技术研究,有兴趣的大家探讨探讨
评论日期:2008年02月25日 00:00:00
评论人:hrjm1314
能不能提供一个.net环境下 好一点的tabs的列子啊?谢谢!期待!
评论日期:2008年05月29日 00:00:00
评论人:kevin
孟老师:
为什么我这个不行呢!我把代码都分离开来了!html是html里面的! 其他代码都是双击写入的!
我现在只能显示一张照片!其他GridView控件都不存在了!
我在Page_Load事件 跟 绑定GridView事件中都写了关于连接库 以及绑定功能!
评论日期:2008年05月29日 00:00:00
评论人:kevin
这是我在Default.aspx.cs中的代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
string strconn = "server=(local);database=WebSiteDemo;uid=sa;pwd=";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
//SqlConnection cnn = new SqlConnection(strconn);
//SqlCommand cmd2 = new SqlCommand("select * from DataTable where id =" + Request.QueryString["id"], cnn);
//cnn.Open();
//SqlDataReader reader = cmd2.ExecuteReader();
//if (reader.Read())
//{
// Response.Clear();
// Response.AddHeader("Content-Type", reader["ConentType"].ToString());
// Response.BinaryWrite((byte[])reader["Photo"]);
//}
//reader.Close();
//cnn.Dispose();
}
protected void FileUpload_Click(object sender, EventArgs e)
{
Stream fileStream = fileUpload.PostedFile.InputStream;
if (fileStream.Length < 1)
{
this.Msg.Text = "请选择图片文件";
return;
}
int fileSize = fileUpload.PostedFile.ContentLength;
byte[] file = new byte[fileSize];
fileStream.Read(file,0,fileSize);
string fileType = fileUpload.PostedFile.ContentType;
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cmd = new SqlCommand("insert into DataTable (UserName,ConentType,Photo) values (@username,@contenttype,@photo)", conn);
cmd.Parameters.AddWithValue("@username",txtusername.Text);
cmd.Parameters.AddWithValue("@contenttype", fileType);
cmd.Parameters.AddWithValue("@photo",file);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect(Request.RawUrl);
}
private void BindGridView()
{
SqlConnection con = new SqlConnection(strconn);
SqlCommand cmd1 = new SqlCommand("select * from DataTable order by id desc",con);
SqlDataReader dr = cmd1.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.AddHeader("ConentType",dr["ConentType"].ToString());
Response.BinaryWrite((byte[])dr["Photo"]);
}
try
{
con.Open();
gv.DataSource = cmd1.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
gv.DataBind();
}
catch(Exception Sql)
{
Response.Write("连接库失败:"+Sql.ToString());
}
}
public string FormatURL(object strURL)
{
return "Default.aspx?ID=" + strURL.ToString();
}
}
下面的是我在Default.asp中的一段重要代码:
<td align=center>
<asp:GridView runat="server" ID="gv" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="姓名"><ItemTemplate><%#Eval("UserName")%></ItemTemplate></asp:TemplateField>
<asp:TemplateField HeaderText="图片"><ItemTemplate><%#FormatURL(Eval("id"))%></ItemTemplate></asp:TemplateField>
</Columns>
</asp:GridView>
</td>
评论日期:2008年05月29日 00:00:00
评论人:kevin
您能给我看下哪错了吗?
评论日期:2008年06月02日 00:00:00
评论人:FY100
SQL的可以哦。。就不知access的数据库类型如何设置!!!!!孟老师能不能讲下!!!
评论日期:2008年06月02日 00:00:00
评论人:fy100
我的SQL:
<form id="MengXianhui" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#Eval("UserName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<img src="<%#FormatURL(Eval("id")) %>" /></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
姓名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
照片:<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="上传" OnClick="Button1_Click"></asp:Button>
<p>
<asp:Label ID="Msg" runat="server" ForeColor="Red"></asp:Label></p>
</form>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class DefaultSQL : System.Web.UI.Page
{
string strCnn = "Persist Security Info=False;User ID=sa;Password=rts2008;Initial Catalog=Image2SQL;Server=(local);";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGrid();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
System.IO.Stream fileDataStream = FileUpload1.PostedFile.InputStream;
if (fileDataStream.Length < 1)
{
Msg.Text = "请选择文件。";
return;
}
//得到文件大小
int fileLength = FileUpload1.PostedFile.ContentLength;
//创建数组
byte[] fileData = new byte[fileLength];
//把文件流填充到数组
fileDataStream.Read(fileData, 0, fileLength);
//得到文件类型
string fileType = FileUpload1.PostedFile.ContentType;
//构建数据库连接,SQL语句,创建参数
SqlConnection myConnection = new SqlConnection(strCnn);
SqlCommand command = new SqlCommand("INSERT INTO UserPhoto (UserName,ContentType,Photo)" +
"VALUES (@UserName,@ContentType,@Photo)", myConnection);
command.Parameters.AddWithValue("@UserName", TextBox1.Text);
command.Parameters.AddWithValue("@ContentType", fileType);
command.Parameters.AddWithValue("@Photo", fileData);
//打开连接,执行查询
myConnection.Open();
command.ExecuteNonQuery();
myConnection.Close();
Response.Redirect(Request.RawUrl);
}
private void BindGrid()
{
SqlConnection myConnection = new SqlConnection(strCnn);
SqlCommand myCommand = new SqlCommand("SELECT * FROM UserPhoto Order By id DESC", myConnection);
try
{
myConnection.Open();
GridView1.DataSource = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
GridView1.DataBind();
}
catch (Exception SQLexc)
{
Response.Write("提取数据时出现错误:" + SQLexc.ToString());
}
}
protected string FormatURL(object strArgument)
{
return "ReadImage.aspx?id=" + strArgument.ToString();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using System.Data.SqlClient;
public partial class ReadImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
////构建数据库连接,SQL语句,创建参数ACCESS数据库使用本注释部分
//string strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Image2Access.mdb");
//OleDbConnection myConnection = new OleDbConnection(strCnn);
//OleDbCommand command = new OleDbCommand("select * from Person Where PersonID =" + Request.QueryString["id"], myConnection);
//myConnection.Open();
//OleDbDataReader dr = command.ExecuteReader();
//if (dr.Read())
//{
// Response.Clear();
// Response.AddHeader("Content-Type", dr["PersonImageType"].ToString());
// Response.BinaryWrite((byte[])dr["PersonImage"]);
//}
//dr.Close();
//myConnection.Dispose();
//构建数据库连接,SQL语句,创建参数
string strCnn = "Persist Security Info=False;User ID=sa;Password=rts2008;Initial Catalog=Image2SQL;Server=(local);";
SqlConnection myConnection = new SqlConnection(strCnn);
SqlCommand command = new SqlCommand("select * from UserPhoto Where id =" + Request.QueryString["id"], myConnection);
myConnection.Open();
SqlDataReader dr = command.ExecuteReader();
if (dr.Read())
{
Response.Clear();
Response.AddHeader("Content-Type", dr["ContentType"].ToString());
Response.BinaryWrite((byte[])dr["Photo"]);
}
dr.Close();
myConnection.Dispose();
}
}
评论日期:2008年09月06日 00:00:00
评论人:
推荐给Web程序员,
学习网络赚钱 [ www.888RMB.com.cn ] 为中国赚钱网站,
提供赚钱教程、赚钱经验、赚钱 秘籍、赚钱项目、赚钱产品, 为想赚钱的人群提供一个赚钱的网络平台
发表评论:
(由于众所周知的原因,评论需要审核后才能显示,请勿重复发评论。谢谢!!)
标题:
用户名:
内容:
验证码:
请输入右边图像中的文字。