问题描述
使用FileUpload控件上传图片,图片上传不到文件夹,数据库也没有写入图片的表,图片无法显示。但其他都正常,都能显示前台页面代码:<bodystyle="background-image:url(../images/right.png);background-repeat:no-repeat;"><formid="form1"runat="server"><div><br/><br/><br/><br/> <asp:DetailsViewID="DetailsView1"runat="server"AutoGenerateRows="False"DataKeyNames="news_id"DataSourceID="newsadd1"Height="352px"Width="700px"><Fields><asp:BoundFieldDataField="news_id"HeaderText="新闻编号"InsertVisible="False"ReadOnly="True"SortExpression="news_id"><HeaderStyleHeight="20px"Width="100px"/></asp:BoundField><asp:BoundFieldDataField="news_title"HeaderText="新闻标题"SortExpression="news_title"><HeaderStyleHeight="25px"/></asp:BoundField><asp:TemplateFieldHeaderText="新闻内容"SortExpression="news_content"><EditItemTemplate><asp:TextBoxID="TextBox1"runat="server"Text='<%#Bind("news_content")%>'Width="199px"></asp:TextBox></EditItemTemplate><InsertItemTemplate><CE:EditorID="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"><FrameStyleBackColor="White"BorderColor="#C0C0C0"BorderStyle="Solid"BorderWidth="1px"CssClass="CuteEditorFrame"Height="100%"Width="550px"/></CE:Editor></InsertItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("news_content")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:BoundFieldDataField="news_time"DataFormatString="{0:d}"HeaderText="发布时间"HtmlEncode="False"SortExpression="news_time"><HeaderStyleHeight="20px"/></asp:BoundField><asp:TemplateFieldHeaderText="新闻图片"SortExpression="news_photo"><EditItemTemplate><asp:TextBoxID="TextBox2"runat="server"Text='<%#Bind("news_photo")%>'></asp:TextBox></EditItemTemplate><InsertItemTemplate><asp:FileUploadID="FileUpload1"runat="server"/></InsertItemTemplate><ItemTemplate><asp:LabelID="Label2"runat="server"Text='<%#Bind("news_photo")%>'></asp:Label></ItemTemplate><HeaderStyleHeight="30px"/></asp:TemplateField><asp:BoundFieldDataField="news_author"HeaderText="新闻作者"SortExpression="news_author"><HeaderStyleHeight="20px"/></asp:BoundField><asp:CommandFieldButtonType="Button"ShowInsertButton="True"/></Fields></asp:DetailsView><asp:AccessDataSourceID="newsadd1"runat="server"DataFile="~/App_Data/jinhai.mdb"DeleteCommand="DELETEFROM[tb_news]WHERE[news_id]=?"InsertCommand="INSERTINTO[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:ParameterName="news_id"Type="Int32"/></DeleteParameters><UpdateParameters><asp:ParameterName="news_title"Type="String"/><asp:ParameterName="news_content"Type="String"/><asp:ParameterName="news_time"Type="DateTime"/><asp:ParameterName="news_author"Type="String"/><asp:ParameterName="news_photo"Type="String"/><asp:ParameterName="news_id"Type="Int32"/></UpdateParameters><InsertParameters><asp:ParameterName="news_title"Type="String"/><asp:ParameterName="news_content"Type="String"/><asp:ParameterName="news_time"Type="DateTime"/><asp:ParameterName="news_author"Type="String"/><asp:ParameterName="news_photo"Type="String"/></InsertParameters></asp:AccessDataSource></div></form></body>后台页面代码:usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclassadmin_newsadd:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){DetailsView1.DefaultMode=DetailsViewMode.Insert;}protectedvoidDetailsView1_PageIndexChanging(objectsender,DetailsViewPageEventArgse){}protectedvoidDetailsView1_ItemInserting(objectsender,DetailsViewInsertEventArgse){FileUploadfilel;filel=(FileUpload)DetailsView1.FindControl("fileupload1");stringfilePath;filePath=Server.MapPath("../newsimage/"+filel.FileName);filel.SaveAs(filePath);newsadd1.InsertParameters["news_photo"].DefaultValue=filel.FileName;}}
解决方案
解决方案二:
帮忙UP吧。。。没有异常提示吗?权限开了吗???断点看一下卡到哪里了,然后具体问题具体分析,这么COPY出来的代码很难帮您分析。。。
解决方案三:
看来只有调试了,光看代码也看不出个名堂来。