那位大佬帮我写下ASP网站下 sqlite数据库存取照片的代码啊,网上搜的要改好多,我不会啊!
那位大佬帮我写下ASP网站下 sqlite数据库存取照片的代码啊,网上搜的要改好多,我不会啊!
这是一个SQLite数据库的存取照片问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2019-08-20 00:57关注
给你完整做了一个
代码下载:https://download.csdn.net/download/caozhy/11580879
default.aspx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SQLite; using System.Data; namespace Q773503 { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { var img = FileUpload1.FileBytes; var datapath = Server.MapPath("~/App_Data/"); SQLiteConnection conn = new SQLiteConnection("data source=" + datapath + "db.db3;version=3;"); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.CommandText = "INSERT INTO tb(img) VALUES(@im)"; SQLiteParameter param = new SQLiteParameter("@im", DbType.Binary, img.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, img); cmd.Parameters.Add(param); cmd.Connection = conn; cmd.ExecuteNonQuery(); Response.Redirect("showimg.aspx"); } } }
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Q773503._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <h2> Welcome to ASP.NET! </h2> <p> To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>. </p> <p> You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409" title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>. </p> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> </asp:Content>
showimage.aspx
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SQLite; using System.Data; namespace Q773503 { public partial class showimg : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { var datapath = Server.MapPath("~/App_Data/"); SQLiteConnection conn = new SQLiteConnection("data source=" + datapath + "db.db3;version=3;"); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); cmd.CommandText = "SELECT * FROM tb ORDER BY id DESC"; cmd.Connection = conn; var reader = cmd.ExecuteReader(); reader.Read(); Response.ContentType = "image/jpeg"; Response.OutputStream.Write((byte[])reader["img"], 0, ((byte[])reader["img"]).Length); Response.End(); } } }
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="showimg.aspx.cs" Inherits="Q773503.showimg" %>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 1
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog