C# 如何从datagrid在picturebox中显示图像?

C# 如何从datagrid在picturebox中显示图像?,c#,sql,datagridview,picturebox,C#,Sql,Datagridview,Picturebox,我正在使用Windows窗体应用程序,我有SQL数据库,其中包含表成员和列:id、fname、lname、性别、电话、已创建、电子邮件和图片(图片已保存。我正在使用绑定的DataGrid和除id列以外的所有列。我希望picturebox显示所选行的图像,我尝试了联机找到的所有内容,但什么都没有 这是表查询: CREATE TABLE [dbo].[members]( [id] [int] IDENTITY(1,1) NOT NULL, [fname] [varchar](50) NOT NULL

我正在使用Windows窗体应用程序,我有SQL数据库,其中包含表成员和列:id、fname、lname、性别、电话、已创建、电子邮件和图片(图片已保存。我正在使用绑定的DataGrid和除id列以外的所有列。我希望picturebox显示所选行的图像,我尝试了联机找到的所有内容,但什么都没有

这是表查询:

CREATE TABLE [dbo].[members](
[id] [int] IDENTITY(1,1) NOT NULL,
[fname] [varchar](50) NOT NULL,
[lname] [varchar](50) NOT NULL,
[gender] [varchar](10) NOT NULL,
[telephone] [varchar](20) NOT NULL,
[created] [date] NULL,
[picture] [image] NULL,
[email] [varchar](50) NULL,
约束[PK__成员__3213E83F00551192]主键群集

这是显示列的代码:

DataGridViewRow row = dataGridView1.Rows[e.RowIndex];

        nameText.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
        lnameText.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
        genderText.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
        telephoneText.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
        datecreaText.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
        emailText.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();



        var data = (Byte[])(row.Cells[6].Value);
        var stream = new MemoryStream(data);
        pictureBox1.Image = Image.FromStream(stream);

有人能帮我解决这个问题3天,但我无法解决它。

为什么您要从行而不是从
dataGridView1.CurrentRow.Cells[6]获取图像数据.Value
?可能不是问题所在,但不建议键入。如果可以,您可能应该使用varbinary。似乎您应该使用数据源,而不是用户界面显示元素。请注意,
我有SQL数据库
什么都没有说-许多数据库使用SQL。请阅读并记录结果,是否有
行.Cells[6]。值
?使用调试器检查其大小等。。!