那位大佬帮我写下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 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)