我想做购物网站,想做这样一个功能。用户模糊查询后,能显示所查所有商品的图片和名字 。
这个咋弄呢?我只能做到用户查完整名字,显示一个图片 和商品名字。
另外有个大佬帮我写了二进制流读取数据库图片的功能
第一个网页是起始网页
对应后台
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();
}
}