图片框中的Image没有变化

The Image in the picture box does not change

我需要帮助。我正在使用 gridview 中的数据来填充文本框和图片框。当我单击一行时,文本框会填满。但是图片框只显示一张图片。不管我在哪一行 select 显示相同的图像。请我是 c# 的新手,我需要帮助。这是我到目前为止所做的 private void viewMemberGrid_CellClick(对象发送者,DataGridViewCellEventArgs e) {

        DataGridViewRow dr = viewMemberGrid.SelectedRows[0];
        GmemIDBox.Text = dr.Cells[0].Value.ToString();

        GsurnameBox.Text = dr.Cells[1].Value.ToString();
        GfirstnameBox.Text = dr.Cells[2].Value.ToString();
        GphoneBox.Text = dr.Cells[3].Value.ToString();
        memDeptBox.Text = dr.Cells[7].Value.ToString();
        memPortBox.Text = dr.Cells[8].Value.ToString();
        GaddBox.Text = dr.Cells[5].Value.ToString();
        GdobBox.Text = dr.Cells[6].Value.ToString();

        string select = "Select NEWMEMBER.MemberID, Surname, Firstname, PhoneNumber, MemberPic, HomeAddress,DOB,DeptID,PortfolioDesc from NEWMEMBER inner join Pictures on NEWMEMBER.MemberID = Pictures.MemberID join PortfolioDescription on PortfolioDescription.PortfolioId = NEWMEMBER.PortfolioID";
        SqlConnection c = new SqlConnection("Data Source=.;Initial Catalog=Cmanager;Integrated Security=True");
        SqlCommand cmd = new SqlCommand(select, c);

        try
        {
            c.Open();
            SqlDataReader dro = cmd.ExecuteReader();

            if (dro.Read())
            {
                byte[] picarr = (byte[])dro["MemberPic"];
                MemoryStream ms = new MemoryStream(picarr);
                ms.Seek(0, SeekOrigin.Begin);
                memPicBox.Image = Image.FromStream(ms);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        c.Close();

    } 

对您的 select 声明稍作修改

;

不知道你数据库中的MemberID Column是Number还是Varchar

.

;

如果是数字

string select = "Select NEWMEMBER.MemberID, Surname, Firstname, PhoneNumber, MemberPic, HomeAddress,DOB,DeptID,PortfolioDesc from NEWMEMBER inner join Pictures on NEWMEMBER.MemberID = Pictures.MemberID join PortfolioDescription on PortfolioDescription.PortfolioId = NEWMEMBER.PortfolioID Where NEWMEMBER.MemberID = " + dr.Cells[0].Value.ToString();

或者如果是 Varchar

string select = "Select NEWMEMBER.MemberID, Surname, Firstname, PhoneNumber, MemberPic, HomeAddress,DOB,DeptID,PortfolioDesc from NEWMEMBER inner join Pictures on NEWMEMBER.MemberID = Pictures.MemberID join PortfolioDescription on PortfolioDescription.PortfolioId = NEWMEMBER.PortfolioID Where NEWMEMBER.MemberID = '" + dr.Cells[0].Value.ToString() + "'";