您的位置:首页 > 数据库

linq to sql 上传,显示图片

2015-12-14 16:29 453 查看
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
tbPath.Text = ofd.FileName;
}
}

private void button2_Click(object sender, EventArgs e)
{
ShiJiYuanDataContext cxt = new ShiJiYuanDataContext();
OtherImg otherImg = new OtherImg();

FileStream fs = new FileStream(tbPath.Text, FileMode.Open, FileAccess.Read);

byte[] bytes = new byte[fs.Length];

fs.Read(bytes, 0, (int)fs.Length);

otherImg.img = bytes;

cxt.OtherImgs.InsertOnSubmit(otherImg);

cxt.SubmitChanges();

MemoryStream ms = new MemoryStream(bytes);

Image img = Image.FromStream(ms);

this.pictureBox1.Image = img;
}

private void button3_Click(object sender, EventArgs e)
{
ShiJiYuanDataContext cxt = new ShiJiYuanDataContext();

OtherImg otherImg = cxt.OtherImgs.SingleOrDefault(p => p.id.ToString() == tbId.Text);

byte[] bytes = new byte[otherImg.img.Length];

bytes = otherImg.img;

MemoryStream ms = new MemoryStream(bytes);

Image img = Image.FromStream(ms);

this.pictureBox1.Image = img;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: