使用FileUpload控件上传图片,上传不到文件夹,数据库也没有写入,图片无法显示。
使用FileUpload控件上传图片,图片上传不到文件夹,数据库也没有写入图片的表,图片无法显示。但其他都正常,都能显示前台页面代码:
<body style="background-image: url(../images/right.png); background-repeat: no-repeat;">
<form id="form1" runat="server">
<div>
<br />
<br />
<br />
<br />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="news_id"
DataSourceID="newsadd1" Height="352px" Width="700px">
<Fields>
<asp:BoundField DataField="news_id" HeaderText="新闻编号" InsertVisible="False" ReadOnly="True"
SortExpression="news_id">
<HeaderStyle Height="20px" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="news_title" HeaderText="新闻标题" SortExpression="news_title">
<HeaderStyle Height="25px" />
</asp:BoundField>
<asp:TemplateField HeaderText="新闻内容" SortExpression="news_content">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("news_content") %>' Width="199px"></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<CE:Editor ID="Editor1" runat="server" AutoConfigure="Simple" AutoParseClasses="True"
BorderColor="#C0C0C0" CodeViewTemplateItemList="Save,Print,Cut,Copy,Paste,Find,ToFullPage,FromFullPage,SelectAll"
EditorOnPaste="ConfirmWord" MaxHTMLLength="0" MaxTextLength="0" Text='<%# Bind("news_content", "{0}") %>'
Width="550px">
<FrameStyle BackColor="White" BorderColor="#C0C0C0" BorderStyle="Solid" BorderWidth="1px"
CssClass="CuteEditorFrame" Height="100%" Width="550px" />
</CE:Editor>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("news_content") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="news_time" DataFormatString="{0:d}" HeaderText="发布时间"
HtmlEncode="False" SortExpression="news_time">
<HeaderStyle Height="20px" />
</asp:BoundField>
<asp:TemplateField HeaderText="新闻图片" SortExpression="news_photo">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("news_photo") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("news_photo") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Height="30px" />
</asp:TemplateField>
<asp:BoundField DataField="news_author" HeaderText="新闻作者" SortExpression="news_author">
<HeaderStyle Height="20px" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:AccessDataSource ID="newsadd1" runat="server" DataFile="~/App_Data/jinhai.mdb"
DeleteCommand="DELETE FROM [tb_news] WHERE [news_id] = ?" InsertCommand="INSERT INTO [tb_news] ([news_title], [news_content], [news_time], [news_author], [news_photo]) VALUES (?, ?, ?, ?, ?)"
SelectCommand="SELECT * FROM [tb_news]" UpdateCommand="UPDATE [tb_news] SET [news_title] = ?, [news_content] = ?, [news_time] = ?, [news_author] = ?, [news_photo] = ? WHERE [news_id] = ?">
<DeleteParameters>
<asp:Parameter Name="news_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="news_title" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
<asp:Parameter Name="news_author" Type="String" />
<asp:Parameter Name="news_photo" Type="String" />
<asp:Parameter Name="news_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="news_title" Type="String" />
<asp:Parameter Name="news_content" Type="String" />
<asp:Parameter Name="news_time" Type="DateTime" />
<asp:Parameter Name="news_author" Type="String" />
<asp:Parameter Name="news_photo" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
后台页面代码:
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;
public partial class admin_newsadd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DetailsView1.DefaultMode = DetailsViewMode.Insert;
}
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
}
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
FileUpload filel;
filel = (FileUpload)DetailsView1.FindControl("fileupload1");
string filePath;
filePath = Server.MapPath("../newsimage/" + filel.FileName);
filel.SaveAs(filePath);
newsadd1.InsertParameters["news_photo"].DefaultValue = filel.FileName;
}
}
--------------------编程问答-------------------- 帮忙UP吧。。。
没有异常提示吗?权限开了吗???
断点看一下卡到哪里了,然后具体问题具体分析,这么COPY出来的代码很难帮您分析。。。 --------------------编程问答-------------------- 看来只有调试了,光看代码也看不出个名堂来。 --------------------编程问答-------------------- http://www.cnblogs.com/neozhu/archive/2008/05/19/1202588.html
http://blog.csdn.net/love_may555/archive/2008/09/06/2891936.aspx
补充:.NET技术 , ASP.NET