MAHSA_RE2001
عضو جدید
سلام
یک سوال فوری دارم
چطور میشه یک عکس را در db ,# c قرار داد.
یک سوال فوری دارم
چطور میشه یک عکس را در db ,# c قرار داد.
سلام
یک سوال فوری دارم
چطور میشه یک عکس را در db ,# c قرار داد.
public byte[] ReadFile(string sPath)
{
byte[] data = null;
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fStream);
data = br.ReadBytes((int)numBytes);
return data;
}
byte[] imageData = ReadFile("آدرس فایل عکس مورد نظر");
خب کد رو همین جا بزارین تا بقیه هم استفاده کنن...پاسخ دوستمون درست هست ولي كامل نيست
اگر كد را خواستي به من ايميل بزن تا كد رو برات بفرستم
vahid.hossaini@gmail.com
public Image selectPesrsonImage(string ID)
{
Image newImage = null;
//
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select photo from PersonelInfo where ID='" + ID + "'";
DataL DbRun = new DataL(false);
if (DbRun.ExecScalarPHOTO(cmd, cmd.CommandText).ToString() != "")
{
DbRun = new DataL(false);
byte[] b = (byte[])DbRun.ExecScalarPHOTO(cmd, cmd.CommandText);
using (MemoryStream stream = new MemoryStream(b))
{
newImage = Image.FromStream(stream);
}
}
return newImage;
}
public object ExecScalarPHOTO(SqlCommand MyCmd, string commandtext)
{
if (checkProgramVersion.checkProgram())
{
Object returnValue;
//
MyCmd.CommandText = commandtext;
MyCmd.CommandType = CommandType.Text;
MyCmd.Connection = Mycn;
if (Mycn.State == ConnectionState.Closed)
{
Mycn.Open();
}
//
returnValue = MyCmd.ExecuteScalar();
Mycn.Close();
Mycn.Dispose();
return returnValue;
}
else
{
return null;
}
}
[LEFT]staticvoid Save()
{
string filename = @"C:\Pic.jpg";
byte[] btemp = File.ReadAllBytes(filename);
SqlConnection con = newSqlConnection("server=localhost;uid=sa;pwd=Pass;database= dbname0");
con.Open();
SqlCommand cmd = newSqlCommand("insert into T1 (Pic)values(@PictureCul)", con);
cmd.Parameters.Add("@PictureCul", SqlDbType.Image).Value = btemp;
cmd.ExecuteNonQuery();
}
staticvoid load()
{
string filename = "c:\\a.jpg";
SqlConnection con = newSqlConnection("server=localhost;uid=sa;pwd=Pass;database= dbname0");
con.Open();
SqlCommand cmd = newSqlCommand("select Pic from T1 ", con);
SqlDataReader dr = cmd.ExecuteReader();
byte[] btemp = newbyte[100000];
FileStream fs = newFileStream(filename, FileMode.Create, FileAccess.Write);
if (dr.Read())
{
int count=0;
long size = 0;
while ((count = (int)dr.GetBytes(0, size, btemp, 0, btemp.Length)) > 0)
{
fs.Write(btemp, 0, count);
size += count;
}
}
fs.Close();
}[/LEFT]
Thread starter | عنوان | تالار | پاسخ ها | تاریخ |
---|---|---|---|---|
نمایش عکس ذخیره شده در پایگاه داده از طریق دیتاگرید | C#.NET | 10 | ||
H | ذخیره عکس در بانک اطلاعاتی اس کیول | C#.NET | 2 | |
M | نمایش عکس ذخیره شده در sql در gidview در محیط c#.net | C#.NET | 7 | |
M | ذخیره کردن عکس در دیتا بیس | C#.NET | 5 | |
S | ذخیره کاراکترهای وارد شده در هر جای ویندوز | C#.NET | 1 |