qq_43412960 2019-08-23 09:19 采纳率: 78.6%
浏览 341
已采纳

这是一个.net的比较高级的问题

我想做购物网站,想做这样一个功能。用户模糊查询后,能显示所查所有商品的图片和名字 。
这个咋弄呢?我只能做到用户查完整名字,显示一个图片 和商品名字。图片说明

另外有个大佬帮我写了二进制流读取数据库图片的功能
第一个网页是起始网页
图片说明

对应后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string name = TextBox1.Text;
        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,name) VALUES(@im,@nam)";
        SQLiteParameter param1 = new SQLiteParameter("@nam", DbType.String, name.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, name);
        SQLiteParameter param = new SQLiteParameter("@im", DbType.Binary, img.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, img);

        cmd.Parameters.Add(param);
        cmd.Parameters.Add(param1);

        cmd.Connection = conn;
        cmd.ExecuteNonQuery();
        Response.Redirect("showimg.aspx");
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
}

第二个显示网页 showing.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;
using System.Data.SqlClient;
using System.Data.SQLite;
public partial class showing : 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     where  name='%11%'  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();
    }


}

  • 写回答

1条回答

  • threenewbee 2019-08-23 09:32
    关注

    sql = "select * from table where 商品名字 like %'" + 关键字 + "%'";

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘