如何显示/检索从datagridview到picturebox C#的图像路径?

时间:2019-01-30 21:53:47

标签: c# sql sql-server

图像的数据类型是Varchar(max)sqlserver,有人可以帮助我吗?

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {

        if (e.RowIndex >= 0)
        {
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];

            PCode.Text = row.Cells[0].Value.ToString();
            Des.Text = row.Cells[1].Value.ToString();
            Pprice.Text = row.Cells[2].Value.ToString();
            comboBox1.Text = row.Cells[3].Value.ToString();

            var test = (Byte[])(row.Cells["Img"].Value);

            var stream = new MemoryStream(test);
            pb.Image = Image.FromStream(stream);

            var path = System.IO.Path.GetDirectoryName(
            System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            path = path.Substring(6);
            path = path + "\\images" + "/" + test;
            File.Copy(imgLocation, path);

        }
    }

0 个答案:

没有答案