PDA

View Full Version : نحوه نمایش عکس با استفاده از داده های Binary



hirkania_ilp
سه شنبه 31 فروردین 1389, 11:00 صبح
من نیاز فوری به کمک دارم:
برای نمایش عکس در ASP.NET از روی داده از نوع binary data دچار مشکل هستم! کد ذخیره سازیم به صورت زیر است اما در نمایش نمی دونم چه کنم!اگر لینک مرتبط هم می دونید بگید ممنون می شم!:




protected void btnEdit_Click(object sender, EventArgs e)
{
string st = Session["userId"].ToString();

Stream imgStream = fupImage.PostedFile.InputStream;
int imgLen = fupImage.PostedFile.ContentLength;
string imgContentType = fupImage.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);



//byte[] imgBinaryData = fupImage.PostedFile.InputStream;
//DataLayer.UserData userData = new DataLayer.UserData();
if(user.EditUserData(st,txtName.Text, txtUserFamily.Text, txtTell1.Text, txtTell2.Text,
txtMobile.Text, txtFax.Text, txtAddress.Text, txtEmail.Text, TxtWebSite.Text,
txtLoginName.Text, txtPassword.Text, drpGroupUser.SelectedValue.ToString() ,imgBinaryData , txtCompName.Text)
)
lblSuccess.Text = "عملیات با موفقیت انجام شد";
else
lblError.Text = "به علت بروز خطا عملیات متوقف شد";

Response.Redirect("~/UserDataPreview.aspx");

}




و در تابع edituser هم :




public bool EditUserData(string userId, string userName, string userFamily, string userTell1,
string userTell2, string userMobile, string userFax, string userAddress,
string userEmail, string userWebsite, string LoginName, string Password,
string userGrpID,
byte[] userImage,
string CompName)
{


SqlCommand command = new SqlCommand();
string sql = "UPDATE users "
+ "SET userName = @userName, "
+ "userFamily = @userFamily, "
+ "userGrpID = @userGrpID, "
+ "userTell1 = @userTell1, "
+ "userTell2 = @userTell2, "
+ "userMobile = @userMobile, "
+ "userFax = @userFax, "
+ "userAddress = @userAddress, "
+ "userEmail = @userEmail, "
+ "userWebsite = @userWebsite, "
+ "LoginName = @LoginName, "
+ "Password = @Password, "
+ "userImage =@userImage, "
+ "CompName = @CompName "
+ "WHERE userID = @userID ";


SqlParameter pImage = new SqlParameter("userImage", SqlDbType.Image);
pImage.Direction = ParameterDirection.Input;
pImage.Value = userImage;
command.Parameters.Add(pImage);

SqlParameter pUserID = new SqlParameter("userID", SqlDbType.Int);
pUserID.Direction = ParameterDirection.Input;
pUserID.Value = userId;
command.Parameters.Add(pUserID);

SqlParameter pUserName = new SqlParameter("userName", SqlDbType.NVarChar,100);
pUserName.Direction = ParameterDirection.Input;
pUserName.Value = userName;
command.Parameters.Add(pUserName);

SqlParameter pUserFamily = new SqlParameter("userFamily", SqlDbType.NVarChar,100);
pUserFamily.Direction = ParameterDirection.Input;
pUserFamily.Value = userFamily;
/*if (userFamily != "")
pUserFamily.Value = userFamily;
else
pUserFamily.Value = "-";*/
command.Parameters.Add(pUserFamily);

SqlParameter pUserGrpID = new SqlParameter("userGrpID", SqlDbType.Int);
pUserGrpID.Direction = ParameterDirection.Input;
pUserGrpID.Value = userGrpID;
command.Parameters.Add(pUserGrpID);

SqlParameter pUserTell1 = new SqlParameter("userTell1", SqlDbType.NVarChar,50);
pUserTell1.Direction = ParameterDirection.Input;
pUserTell1.Value = userTell1;
command.Parameters.Add(pUserTell1);

SqlParameter pUserTell2 = new SqlParameter("userTell2", SqlDbType.NVarChar,50);
pUserTell2.Direction = ParameterDirection.Input;
pUserTell2.Value = userTell2;
command.Parameters.Add(pUserTell2);

SqlParameter pUserMobile = new SqlParameter("userMobile", SqlDbType.NVarChar,50);
pUserMobile.Direction = ParameterDirection.Input;
pUserMobile.Value = userMobile;
command.Parameters.Add(pUserMobile);

SqlParameter pUserFax = new SqlParameter("userFax", SqlDbType.NVarChar,50);
pUserFax.Direction = ParameterDirection.Input;
pUserFax.Value = userFax;
command.Parameters.Add(pUserFax);

SqlParameter pUserAddress = new SqlParameter("userAddress", SqlDbType.NVarChar,200);
pUserAddress.Direction = ParameterDirection.Input;
pUserAddress.Value = userAddress;
command.Parameters.Add(pUserAddress);

SqlParameter pUserEmail = new SqlParameter("userEmail", SqlDbType.NVarChar,50);
pUserEmail.Direction = ParameterDirection.Input;
pUserEmail.Value = userEmail;
command.Parameters.Add(pUserEmail);

SqlParameter pUserWebsite = new SqlParameter("userWebsite", SqlDbType.NVarChar,50);
pUserWebsite.Direction = ParameterDirection.Input;
pUserWebsite.Value = userWebsite;
command.Parameters.Add(pUserWebsite);

SqlParameter pLoginName = new SqlParameter("LoginName", SqlDbType.NVarChar,100);
pLoginName.Direction = ParameterDirection.Input;
pLoginName.Value = LoginName;
command.Parameters.Add(pLoginName);

SqlParameter pPassword = new SqlParameter("Password", SqlDbType.NVarChar,50);
pPassword.Direction = ParameterDirection.Input;
pPassword.Value = Password;
command.Parameters.Add(pPassword);

SqlParameter pCompName = new SqlParameter("CompName", SqlDbType.NVarChar,50);
pCompName.Direction = ParameterDirection.Input;
pCompName.Value = Password;
command.Parameters.Add(pCompName);

command.CommandText = sql;
if (!baseData.ExecQuery(command))
{
return false;
}
else
{
return true;
}

}

eyes_shut_number1
سه شنبه 31 فروردین 1389, 12:51 عصر
rad telerik یه کامپوننت داره به اسن binery image میتونی از اون استفاده کنی

hirkania_ilp
سه شنبه 31 فروردین 1389, 13:11 عصر
ممنون
اما می شه یکم بیشتر توضیح بدید؟
ممنون می شم.

Vahid_moghaddam
سه شنبه 31 فروردین 1389, 13:58 عصر
شاید این لینک ها مفید باشه

http://weblogs.asp.net/cazzu/archive/2003/08/27/25568.aspx

http://www.asp.net/Learn/Data-Access/tutorial-55-cs.aspx

General-Xenon
چهارشنبه 01 اردیبهشت 1389, 00:22 صبح
http://barnamenevis.org/forum/showthread.php?t=215925