ef框架实现数据库的添加图片
- 管理nuget程序包
- 联机
- 找到实体框架
- 添加新项目-c#—实体数据模型
- 新建连接
- 访问方式sql身份验证
- dbmodel选中表格-完成
model里面看到每个表
显示照片
<复杂版>
新建网站窗体
设置静态页面
双击进入cs:
protected void Page_Load(object sender, EventArgs e)
{
dishDBEntities mydb = new dishDBEntities(); //得到数据库实体对象
var allxiancai = mydb.dishTable.Where( c=> c.number.Substring(0,2) =="01");
//查询编号为01开头的记录
int recordcount = allxiancai.Count(); //得到记录总数
this.Label1.Text = "
foreach(var arec in allxiancai) //遍历每条记录
{
this.Label1.Text = this.Label1.Text+"\n"+ "<tr>";
this.Label1.Text = this.Label1.Text + "\n" + "<td>";
this.Label1.Text = this.Label1.Text + "<br />" + arec.name + " ";
this.Label1.Text = this.Label1.Text + arec.peiliao + " ";
this.Label1.Text = this.Label1.Text + arec.price + " ";
this.Label1.Text = this.Label1.Text + "\n" + "</td>";
this.Label1.Text = this.Label1.Text + "\n" + "<td>";
this.Label1.Text = this.Label1.Text + "<img src='" + arec.picture1+"' width='100px' height='50px' />";
this.Label1.Text = this.Label1.Text + "\n" + "</td>";
this.Label1.Text = this.Label1.Text + "\n" + "</tr>";
}
this.Label1.Text = this.Label1.Text + "\n" + "</table>";
}
}
使用repeat控件;