| 发表于:2007-11-26 18:01:226楼 得分:0 |
已经有解决的办法了,很简单, imports system.data imports system.data.oledb public class form3 '下面内容是公共变量,在后面多个事件中都要访问这些变量。 '定义数据库连接对象 dim oledbconnectionstring as string = "provider = microsoft.jet.oledb.4.0 ;data source=d:\student.mdb" dim oledbconnection1 as new oledbconnection(oledbconnectionstring) '定义数据适配器对象 dim sqlstring as string = "select *from 基本情况" dim oledbdataadapter1 as new oledbdataadapter(sqlstring, oledbconnection1) '定义数据集对象 dim dataset1 as new dataset '定义绑定源对象,它的position属性用于确定控件所绑定的位置(绑定到第几条记录) dim bindingsource1 as bindingsource '定义绑定位置变量,第一条记录位置是0 dim position1 as integer private sub form3_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load '用数据适配器对象填充数据集 oledbconnection1.open() oledbdataadapter1.fill(dataset1, "基本情况") oledbconnection1.close() '为绑定源对象赋值 bindingsource1 = new bindingsource(dataset1, "基本情况") '将控件绑定到绑定源对象,默认第0条记录 textbox1.databindings.add("text", bindingsource1, "姓名") textbox2.databindings.add("text", bindingsource1, "性别") textbox3.databindings.add("text", bindingsource1, "学号") textbox4.databindings.add("text", bindingsource1, "出生年月") textbox5.databindings.add("text", bindingsource1, "专业") '为绑定位置变量赋值(bindingcontext是控件的属性,表示“绑定内容”) 'position1 = me.bindingcontext(dataset1, "基本情况").position end sub | | |
|