C#读取数据库IMAGE字段的内容。

C#读取数据库IMAGE字段的内容。,第1张

读取... 读取长二进制为图片..

string sql = "select photo from studentinfo where studentid = " + this.Tag.ToString()

OleDbCommand cmd = new OleDbCommand(sql, connection1)

if (Convert.DBNull != cmd.ExecuteScalar())

pictureBox1.Image = Image.FromStream(new MemoryStream((Byte[])cmd.ExecuteScalar()))

放大就不知道了

保存:

string filename= textBox1.Text//"c:\\IMG_0117.jpg"

BinaryReader reader=null

FileStream myfilestream = new FileStream(filename,FileMode.Open)

try

{

reader=new BinaryReader(myfilestream)

byte[] image = reader.ReadBytes((int)myfilestream.Length)

using (SqlConnection conn = new SqlConnection("server=test05database=esdb2uid=datatranpwd=qyrl"))

{

using (SqlCommand command = conn.CreateCommand())

{

command.CommandText =@"INSERT INTO photo(photo) VALUES (@photo)"

command.Parameters.Add("@photo", image)

conn.Open()

command.ExecuteNonQuery()

conn.Close()

MessageBox.Show("文件保存成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)

}

}

}

catch(IOException ee)

{

MessageBox.Show(ee.Message.ToString())

}

finally

{

if(reader!=null)

reader.Close()

}

反射:在运行状态下,通过class文件对象,去使用构造方法,成员变量,成员方法

方法有三种:

1.类名.class

2.对象.getclass()

3.class.forName("包名.类名")

好处:

只要有一个类或者一个类的对象,就可以得到这个类或对象的所有属性和方法,包括私有的

同步方法

反射成员方法:

1.获取字节码文件

Class c = Class.forName("包名.类名");

2.反射方法

Method m = c.getMethod("反射的方法",方法的参数类型.class)

3.用方法,m.invoke(对象,参数) 对象,c.newInstance ,在A建立对象。

m.invoke(c.newInstance(),参数);

类加载器与反射有什么关系

反射是通过字节码文件对象,将类的字段,方法,构造器等映射成相应的类,并进行各自的 *** 作;

类加载器是通过某个类的.classLoader()方法,将该类的.class文件从硬盘中加载到java虚拟机中,形成字节码文件;

#include  <stdio.h>

exec sql include sqlca

int main(){

    exec sql begin declare section

        char userpasswd[30]="openlab/123456"

        struct{

            int  id

            char name[30]

            double salary

        }emp

    exec sql end   declare section

    exec sql connect:userpasswd

    exec sql declare empcursor cursor for 

        select id,first_name,salary  from 

        s_emp order by salary

    exec sql  open  empcursor

    exec sql  whenever notfound do break

    for(){

    exec sql  fetch empcursor into :emp

    printf("%d:%s:%lf\n",emp.id,emp.name,

                     emp.salary)

    }

    exec sql  close empcursor

    exec sql commit work release    

}

把数据存到结构体里。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/sjk/6631796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-26
下一篇 2023-03-26

发表评论

登录后才能评论

评论列表(0条)

保存