this code inserts in the database
private void btnSave_Click(object sender, EventArgs e)
{
byte[] imageBt = null;
FileStream fstream = new FileStream(this.txtImgPath.Text,FileMode.Open,FileAccess.Read);
BinaryReader Br = new BinaryReader(fstream);
imageBt = Br.ReadBytes((int)fstream.Length);
// byte[] pic = stream.ToArray();
try
{
conDB.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conDB;
command.CommandText = "insert into abaanaCC (CCSpn_CODE,CCFname,CCLname,CCMname,CCDOB,CCgender,CCSchool,CaClass,CCVillage,CCSiblings,CCGuardian,CCContact,CCImage)" +
" values ('" + spn_codetxt.Text + "','" + txtfname.Text + "','" + lnametxt.Text + "','" + mnametxt.Text + "','" + DOBDTPicker1.Text + "','" + gendercomboBox.Text + "','" + schtxt.Text + "','" + classcomboBox.Text + "','" + villatxt.Text + "','" + siblingscombobx.Text + "','" + guardiantxt.Text + "','" + contacttxt.Text + "',@IMG) ";
command.Parameters.Add(new OleDbParameter("@IMG",imageBt));
//command.Parameters.AddWithValue("@IMG",pic);
command.ExecuteNonQuery();
MessageBox.Show("Record Saved");
}
catch (Exception ex)
{
MessageBox.Show("Unable to save" + ex);
}
conDB.Close();
}
then this is for datagridview
private void Update_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'abaanaDataSet.abaanaCC' table. You can move, or remove it, as needed.
this.abaanaCCTableAdapter.Fill(this.abaanaDataSet.abaanaCC);
}
am using the cell click event, such that when a cell is clicked, the contents of that row, that is the CCImage
and CCSpn_CODE
appear. The CCSpn_CODE
appears in Ptxtspn_code
textBox
just fine. The problem is the byte[] image that i'm converting. it's displaying only the image of the first row. how can i make PpicBox
display whatever image from whatever row i click on the datagridView
just like Ptxtspn_code
textBox
private void abaanaCCDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.Ptxtspn_code.Text = this.abaanaCCDataGridView.SelectedRows[0].Cells[this.dataGridViewTextBoxColumn2.Name].Value.ToString();
this.abaanaCCTableAdapter.Fill(this.abaanaDataSet.abaanaCC);
byte[] mydata = (byte[])this.abaanaDataSet.abaanaCC.Rows[0]["CCImage"];
MemoryStream stream = new MemoryStream(mydata);
this.PpicBox.Image =Image.FromStream(stream);
}