night-wolf
سه شنبه 17 دی 1392, 22:22 عصر
با سلام و خسته نباشید ...
دوستان من میخوام تصویری رو بصورت باینری در sql server ثبت کنم و این کار رو کردم
الان میخوام فراخوانی کنم در یک کنترل Image که نمایش بده اما اررور میده لطفا کد رو بررسی کنید
private void Page_Load(object sender, System.EventArgs e)
{
MemoryStream stream = new MemoryStream ();
SqlConnection connection = new
SqlConnection (@”server=127.0.0.1;database=MyData;uid=sa;pwd=y ourpass“);
try
{
connection.Open ();
SqlCommand command = new
SqlCommand (“select Picture from Image“, connection);
byte[] image = (byte[]) command.ExecuteScalar ();
stream.Write (image, 0, image.Length);
Bitmap bitmap = new Bitmap (stream);
Response.ContentType = “image/gif“;
bitmap.Save (Response.OutputStream, ImageFormat.Gif);
}
finally
{
connection.Close ();
stream.Close ();
}
در ضمن این یه مثاله و کانکشن استرینگ اینا دقیق هست و مشکلی نداره چون تو درج راحت درج شد
اینم کد درج
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read (pic, 0, len);
// افزودن تصویر و توضیح تصویر به بانک اطلاعاتی
SqlConnection connection = new
SqlConnection (”server=(local);database=MyData;uid=sa;pwd=your pass“);
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand (“insert into Image(Tasvir)values(' " + pic + " '),connection);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
حالا فقط مشکل اساسی فراخوانی تو یه کنترل image هست لطفا راهنمایی کنید !
ممنون :لبخندساده:
دوستان من میخوام تصویری رو بصورت باینری در sql server ثبت کنم و این کار رو کردم
الان میخوام فراخوانی کنم در یک کنترل Image که نمایش بده اما اررور میده لطفا کد رو بررسی کنید
private void Page_Load(object sender, System.EventArgs e)
{
MemoryStream stream = new MemoryStream ();
SqlConnection connection = new
SqlConnection (@”server=127.0.0.1;database=MyData;uid=sa;pwd=y ourpass“);
try
{
connection.Open ();
SqlCommand command = new
SqlCommand (“select Picture from Image“, connection);
byte[] image = (byte[]) command.ExecuteScalar ();
stream.Write (image, 0, image.Length);
Bitmap bitmap = new Bitmap (stream);
Response.ContentType = “image/gif“;
bitmap.Save (Response.OutputStream, ImageFormat.Gif);
}
finally
{
connection.Close ();
stream.Close ();
}
در ضمن این یه مثاله و کانکشن استرینگ اینا دقیق هست و مشکلی نداره چون تو درج راحت درج شد
اینم کد درج
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read (pic, 0, len);
// افزودن تصویر و توضیح تصویر به بانک اطلاعاتی
SqlConnection connection = new
SqlConnection (”server=(local);database=MyData;uid=sa;pwd=your pass“);
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand (“insert into Image(Tasvir)values(' " + pic + " '),connection);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
حالا فقط مشکل اساسی فراخوانی تو یه کنترل image هست لطفا راهنمایی کنید !
ممنون :لبخندساده: