بعد از چند ساعت کلنجار بالاخره تونستم خیلی دقیق این کارا رو انجام بدم.
راه حلش رو هم اینجا میذارم شاید بدرد یه بنده خدایی خورد :
برای وارد کردن عکسا به tableباید اول اونا رو بصورت باینری کرد و توی یه stream ریخت :
protected static byte[] ReadBitmap2ByteArray(string fileName)
{
using(Bitmap image = new Bitmap(fileName))
{
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
return stream.ToArray();
}
}
بعد با insert into به جدول فرستادشون :
protected static void StoreBlob2DataBase(byte[] content,string text)
{
SqlConnection conn1 = new SqlConnection("Data Source=PDNOTEBOOK\\CSHARPDBPROJECT;Initial Catalog=testDb;Persist Security Info=True;User ID=sa;pwd=a");
conn1.Open();
try
{
// insert new entry into table
SqlCommand insert = new SqlCommand(
"insert into Table_1 (name,pic) values ('"+text+"',@image)", conn1);
SqlParameter imageParameter =
insert.Parameters.Add("@image", SqlDbType.Binary);
imageParameter.Value = content;
imageParameter.Size = content.Length;
insert.ExecuteNonQuery();
}
finally
{
conn1.Close();
}
}
بعد با دو تا دستور پایین این متد ها رو فراخوانی کرد :
byte[] content = ReadBitmap2ByteArray(listBox1.SelectedItem.ToStrin g());
StoreBlob2DataBase(content,textBox1.Text);
----------------------------------
برای بازیابی عکسها از تیبل اول یه dataset ساختم و بعد :
byte[] content = (byte[])dset1.Tables[0].Rows[listBox2.SelectedIndex][1];
MemoryStream stream = new MemoryStream(content);
Image image = new Bitmap(stream);
pictureBox2.Image = image;
pictureBox2.SizeMode = PictureBoxSizeMode.StretchImage;
------------------------------------
امیدوارم مفید بوده باشه.
ضمنا منظور از blob هم :binary long object هست.یعنی چیزایی مثل image و ... .