Hi newbie in coding. I created a from which contain around 12 dynamic picbox and labels. im able to read data from dataset and able to show images in the picbox & text in label. Also able to create individual click event to every picbox.
Now the thing i want to accomplished when i click on a picbox i want to search that binary_data of image of picbox in my table and want to know from which row that binary_data belong. My column contain a field "title". so when row is find out from where the data belong then a textbox1 show the "Title".
Also when i try to insert photo_aray value in oldebcommand its show me error "Error 2 Argument: cannot convert from byte[] to string"
can any one help me in this matter urgent. Thanku in advance
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace library
{
public partial class showingmore : Form
{
private string passvalue;
public string passval
{
get { return passvalue; }
set { passvalue = value; }
}
public showingmore()
{
InitializeComponent();
}
byte[] photo_aray;
private void showingmore_Load_1(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection("Provider=SQLOLEDB;User ID=sa;Password =12345678; Initial Catalog=library; server=raj; TRUSTED_CONNECTION=true;");
OleDbDataAdapter Adap = new OleDbDataAdapter("select * from movie ", con);
DataSet ds = new DataSet();
Adap.Fill(ds);
int icount = ds.Tables[0].Rows.Count;
textBox1.Text = icount.ToString();
int n = 12;
int j = 14;
int k = 479;
int l = 18;
for (int i = 0; i < n; i++)
{
Label labels = new Label();
labels.Text = ds.Tables[0].Rows[i][0].ToString();
labels.Tag = i;
if (i <= 5)
{
labels.Location = new Point(j, k);
j = j + 228;
labels.ForeColor = Color.Gainsboro;
}
else
{
k = 782;
labels.Location = new Point(l, k);
l = l + 228;
labels.ForeColor = Color.Gainsboro;
}
this.Controls.Add(labels);
}
n = 12;
j = 18;
k = 246;
l = 18;
for (int i = 0; i < n; i++)
{
PictureBox picbox = new PictureBox();
picbox.Click += picbox_Click;
picbox.Tag = i;
picbox.Image = null;
if (ds.Tables[0].Rows[i][14] != System.DBNull.Value)
{
photo_aray = (byte[])ds.Tables[0].Rows[i][14];
MemoryStream ms = new MemoryStream(photo_aray);
picbox.Image = Image.FromStream(ms);
}
if (i <= 5)
{
picbox.Location = new Point(j, k);
picbox.Size = new Size(161, 220);
picbox.BackColor = Color.Gainsboro;
j = j + 228;
}
else
{
k = 543;
picbox.Location = new Point(l, k);
picbox.Size = new Size(161, 220);
picbox.BackColor = Color.Gainsboro;
l = l + 228;
}
this.Controls.Add(picbox);
}
}
private void picbox_Click(object sender, EventArgs e)
{
byte[] photo_aray2;
OleDbConnection con = new OleDbConnection("Provider=SQLOLEDB;User ID=sa;Password =12345678; Initial Catalog=library; server=raj; TRUSTED_CONNECTION=true;");
OleDbDataAdapter Adap = new OleDbDataAdapter("select * from movie ", con);
textBox1.Text = passvalue;
DataSet ds = new DataSet();
Adap.Fill(ds);
PictureBox picbox = sender as PictureBox;
if (picbox != null)
{
switch ((int)picbox.Tag)
{
case 0:
textBox1.Text = "1";
picbox.Tag = 0;
textBox3.Text = ds.Tables[0].Rows[0]["picturebox"].ToString();
if (picbox.Image != null)
{
MemoryStream mst = new MemoryStream();
picbox.Image.Save(mst, ImageFormat.Jpeg);
byte[] photo_aray = new byte[mst.Length];
mst.Position = 0;
mst.Read(photo_aray, 0, photo_aray.Length);
textBox4.Text = photo_aray.ToString();
}
break;
case 1:
textBox1.Text = "2";
picbox.Tag = 1;
textBox3.Text = ds.Tables[0].Rows[1]["size"].ToString();
if (picbox.Image != null)
{
MemoryStream mst = new MemoryStream();
picbox.Image.Save(mst, ImageFormat.Jpeg);
byte[] photo_aray = new byte[mst.Length];
mst.Position = 0;
mst.Read(photo_aray, 0, photo_aray.Length);
photo_aray2 = Encoding.ASCII.GetBytes("select * from movie where picturebox='" + photo_aray + "'");
OleDbCommand cmd = new OleDbCommand(photo_aray2, con);
}
break;
case 2:
textBox1.Text = "3";
picbox.Tag = 2;
textBox3.Text = ds.Tables[0].Rows[2]["size"].ToString();
textBox4.Text = ds.Tables[0].Rows[2]["picturebox"].ToString();
break;
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}