问题描述
急!如何解决关于上传图片时不能把数据写入数据表中?ProtectedSubButton1_Click(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesButton1.ClickDimfilePathAsString=""DimfileExtNameAsString=""DimmPathAsStringDimfilenameAsStringDimfileAsStringIfFileUpload1.PostedFile.FileName=""ThenResponse.Write("<scriptlanguage='javascript'runat='server'>window.alert('请选择你要上传的图片!')</script>")ElsefilePath=FileUpload1.PostedFile.FileNamefilename=filePath.Substring(filePath.LastIndexOf("\")+1)fileExtName=filePath.Substring(filePath.LastIndexOf(".")+1)file=FileUpload1.FileName.ToString()If(fileExtName="jpg"OrfileExtName="bmp"OrfileExtName="gif")ThenTryDimsqlstrAsStringDima1AsTConna1=NewTConna1.Initial()a1.OpenConn()mPath=Server.MapPath("upfile/")FileUpload1.PostedFile.SaveAs(mPath+file)DimimageAsImageimage=System.Drawing.Image.FromFile(Server.MapPath("upfile")&file)DimcallbackAsImage.GetThumbnailImageAbortDimcallbackdataAsIntPtrDimnewimageAsImagenewimage=image.GetThumbnailImage(100,100,callback,callbackdata)newimage.Save(Server.MapPath("upfile")+"\small"+file)image.Dispose()newimage.Dispose()sqlstr="insertintozdxm(zd_title,zd_url,zd_smurl,zd_content,zd_addr,zd_author)values('"+Me.TextBox1.Text.Trim()+"','"+file+"','"+"small"+file+"','"+Me.TextBox2.Text.Trim()+"','"+Me.TextBox3.Text.Trim()+"','"+Me.TextBox3.Text.Trim()+"')"DimcomAsSqlCommandcom=NewSqlCommand(sqlstr,a1.GetConn())com.ExecuteNonQuery()me.Label1.Text="添加成功!"CatchexAsExceptionEndTryElseResponse.Write("<scriptlanguage='javascript'runat='server'>window.alert('图片格式不对,只能上传jpg或bmp或gif格式!!')</script>")EndIfEndIfEndSub