|
各位前辈好,小弟新人,初来乍到请多指教。
我在看开发视频中的数据列表展示,将如何listview调用用户模板,模板中有image控件,但是我没看明白,怎么样将用户模板中的image控件绑定到数据库的字段上。
我用的mariadb作为数据库端,其中数据表 test 中有三个字段, id (INT), name(VARCHAR50),picture(MEDIUMBLOG) , 我在用户模板中添加了3个控件:
label1 , label2 和 image1, 分别对应数据表中的三个字段:
label1.DisplayMember = id;
label2.DisplayMember = name;
image1.DisplayMember = picture;
DataTable DT = new DataTable();
DT.Columns.Add("id" );
DT.Columns.Add("name");
DT.Columns.Add("picture", typeof(byte[]) );
MySqlConnection con = new MySqlConnection("Database=test; Data Source = 127.0.0.1; port= 3306; User Id=root; Password=root; ");
con.open();
MySqlCommand cmd = new MySqlCommand("select * from test", con);
cmd.ExecuteQuery();
MySqlDataReader dr = cmd.ExecuteReader();
DT.Load(dr);
listview1.DataSource = DT;
listview1.DataBind();
执行结果,在listview中,用户模板上的label1 和 label2 都能够绑定到DT的id 和 name , 并能够正确的显示出数据表中的内容,但是 image1中显示不出 数据表中MEDIUMBLOG字段中的图像。
请帮我看一下上面的代码错在哪里了?为什么图像字段不能加载到image1kong'j。
|
|