nimam2008
پنج شنبه 15 اردیبهشت 1390, 17:38 عصر
با سلام
من تقریبا تمام تاپیک های مربوط به لود تصویر رو خوندم ولی نتونستم مشکلم رو حل کنم لطفا را کد مورد نیاز رو برام بنویسید چون با راهنمایی هایی که کرده بودین نتونستم کاری از پیش ببرم
من یه عکس رو توسط کد زیر در SQL ذخیره کردم
private byte[] ConvertImageToByte(string ImageLocation)
{
byte[] picture = File.ReadAllBytes(ImageLocation);
return picture;
}
private void button3_Click(object sender, EventArgs e)
{
string queryInd = "insert into TIndicator(Id,Name,Pic) " +
"values (@Id,@Name,@Pic)";
SqlCommand cmdSave = new SqlCommand(queryInd, Connection.Set_Con());
cmdSave.Parameters.AddWithValue("@Id", tbxId.Text);
cmdSave.Parameters.AddWithValue("@Name", tbxName.Text);
cmdSave.Parameters.AddWithValue("@Pic", ConvertImageToByte(openLetter.FileName));
cmdSave.Connection.Open();
cmdSave.ExecuteNonQuery();
cmdSave.Connection.Close();
}
و توسط کد زیر در دیتا گرید فراخوانی می کنم
SqlDataAdapter adapterS = new SqlDataAdapter();
adapterS.SelectCommand = new SqlCommand();
adapterS.SelectCommand.Connection = Connection.Set_Con();
DataSet dsS = new DataSet();
string queryS = "select Id,Name,Pic from TIndicator";
adapterS.SelectCommand.CommandText = queryS;
adapterS.Fill(dsS, "TIndicator");
DGVInd.DataSource = dsS.Tables["TIndicator"];
DGVInd.Columns[0].HeaderText = "شماره";
DGVInd.Columns[1].HeaderText = "نام";
DGVInd.Columns[2].HeaderText = "تصویر";
که البته تصویر در دیتاگرید نمایش داده می شه ولی من میخوام وقتی روی هر کدوم از سطر های دیتاگرید که کلیک می کنم تصویر مربوط به اون سطر در یه Picture Box نمایش داده بشه و وقتی روی تصویری که در Picture Box نمایش داده می شه کلیک می کنم تصویر با یکی از نرم افزار های ویندوز مانند Win Picture and Fax Viewer نمایش داده بشه
با تشکر
من تقریبا تمام تاپیک های مربوط به لود تصویر رو خوندم ولی نتونستم مشکلم رو حل کنم لطفا را کد مورد نیاز رو برام بنویسید چون با راهنمایی هایی که کرده بودین نتونستم کاری از پیش ببرم
من یه عکس رو توسط کد زیر در SQL ذخیره کردم
private byte[] ConvertImageToByte(string ImageLocation)
{
byte[] picture = File.ReadAllBytes(ImageLocation);
return picture;
}
private void button3_Click(object sender, EventArgs e)
{
string queryInd = "insert into TIndicator(Id,Name,Pic) " +
"values (@Id,@Name,@Pic)";
SqlCommand cmdSave = new SqlCommand(queryInd, Connection.Set_Con());
cmdSave.Parameters.AddWithValue("@Id", tbxId.Text);
cmdSave.Parameters.AddWithValue("@Name", tbxName.Text);
cmdSave.Parameters.AddWithValue("@Pic", ConvertImageToByte(openLetter.FileName));
cmdSave.Connection.Open();
cmdSave.ExecuteNonQuery();
cmdSave.Connection.Close();
}
و توسط کد زیر در دیتا گرید فراخوانی می کنم
SqlDataAdapter adapterS = new SqlDataAdapter();
adapterS.SelectCommand = new SqlCommand();
adapterS.SelectCommand.Connection = Connection.Set_Con();
DataSet dsS = new DataSet();
string queryS = "select Id,Name,Pic from TIndicator";
adapterS.SelectCommand.CommandText = queryS;
adapterS.Fill(dsS, "TIndicator");
DGVInd.DataSource = dsS.Tables["TIndicator"];
DGVInd.Columns[0].HeaderText = "شماره";
DGVInd.Columns[1].HeaderText = "نام";
DGVInd.Columns[2].HeaderText = "تصویر";
که البته تصویر در دیتاگرید نمایش داده می شه ولی من میخوام وقتی روی هر کدوم از سطر های دیتاگرید که کلیک می کنم تصویر مربوط به اون سطر در یه Picture Box نمایش داده بشه و وقتی روی تصویری که در Picture Box نمایش داده می شه کلیک می کنم تصویر با یکی از نرم افزار های ویندوز مانند Win Picture and Fax Viewer نمایش داده بشه
با تشکر