0

我有一个这个程序,如果用户单击 datagridview 中的一行:

    private void ListView_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
    {
        try
        {
            if (!ListView.Rows[e.RowIndex].IsNewRow)
            {
                idnum.Text = ListView.Rows[e.RowIndex].Cells[0].Value.ToString();
                CmbPosition.Text = ListView.Rows[e.RowIndex].Cells[1].Value.ToString();
                TxtFirstName.Text = ListView.Rows[e.RowIndex].Cells[2].Value.ToString();
                TxtMiddleName.Text = ListView.Rows[e.RowIndex].Cells[3].Value.ToString();
                TxtLastName.Text = ListView.Rows[e.RowIndex].Cells[4].Value.ToString();
                CmbYearLevel.Text = ListView.Rows[e.RowIndex].Cells[5].Value.ToString();
                CmbCourse.Text = ListView.Rows[e.RowIndex].Cells[6].Value.ToString();
                TxtSchoolYear.Text = ListView.Rows[e.RowIndex].Cells[7].Value.ToString();
                TxtFilePath.Text = ListView.Rows[e.RowIndex].Cells[8].Value.ToString();

                BtnAdd.Enabled = false;

            }
            else
            {
                ClearData();
            }
        }
        catch
        {

        }
    }

并读取数据库,以便每当用户单击datagridview中的一行时,它就可以获取路径并将我保存在数据库中的图像显示到picturebox1。

    public void TabindexChanged()
    {
        MemoryStream ms = new MemoryStream();

        cmd = new SqlCommand("SELECT * FROM DBAdmin WHERE imgPath='" + _dg + "'", sc);
        sc.Open();
        SqlDataReader dr;

        try
        {
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                byte[] picarr = (byte[])dr["imgImage"];
                ms = new MemoryStream(picarr);
                ms.Seek(0, SeekOrigin.Begin);
                _pb.Image = Image.FromStream(ms);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
        finally
        {
            sc.Close();
        }
    }

but it seems that it wont get the imgPath from the database.. does not show up any picture in the picturebox1 whenever a row is selected. 提前致谢。

4

0 回答 0