| 发表于:2007-03-08 14:16:00 楼主 |
跳出个框“更新无法找到tablemapping[ "table "]或datatable "table " 代码如下 dim bm as bindingmanagerbase private da as sqldataadapter private ds as dataset private dtsource as datatable private pagecount as integer private maxrec as integer private pagesize as integer private currentpage as integer private recno as integer private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim dgrdelete = dialogresult try dgrdelete = messagebox.show( "是否要删除记录? ", "confirm delete ", messageboxbuttons.yesno) if dgrdelete = dialogresult.yes then with bm .removeat(.position) end with da.update(ds) ds.acceptchanges() end if catch err as exception messagebox.show(err.message) end try end sub private sub form12_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load dim conn as sqlconnection = new sqlconnection( _ "server=allen;uid=sa;pwd=;database=pubs ") 'set the dataadapter 's query. da = new sqldataadapter( "select * from 发票表 ", conn) ds = new dataset() ' fill the dataset. da.fill(ds, "发票表 ") bm = me.bindingcontext(ds, "发票表 ") ' set the source table. dtsource = ds.tables( "发票表 ") addhandler bm.positionchanged, addressof position_changed position_changed(sender, e) end sub private sub btnnextpage_click(byval sender as system.object, _ byval e as system.eventargs) handles btnnextpage.click 'if the user did not click the "fill grid " button then return if not checkfillbutton() then return 'check if the user clicked the "fill grid " button. if pagesize = 0 then messagebox.show( "set the page size, and then click the " "fill grid " " button! ") return end if currentpage = currentpage + 1 if currentpage > pagecount then currentpage = pagecount 'check if you are already at the last page. if recno = maxrec then messagebox.show( "you are at the last page! ") return end if end if loadpage() end sub private sub btnpreviouspage_click(byval sender as system.object, _ byval e as system.eventargs) handles btnpreviouspage.click if not checkfillbutton() then return if currentpage = pagecount then recno = pagesize * (currentpage - 2) end if currentpage = currentpage - 1 'check if you are already at the first page. if currentpage < 1 then messagebox.show( "you are at the first page! ") currentpage = 1 return else recno = pagesize * (currentpage - 1) end if loadpage() end sub private sub loadpage() dim i as integer dim startrec as integer dim endrec as integer dim dttemp as datatable dim dr as datarow 'duplicate or clone the source table to create the temporary table. dttemp = dtsource.clone if currentpage = pagecount then endrec = maxrec else endrec = pagesize * currentpage end if startrec = recno 'copy the rows from the source table to fill the temporary table. for i = startrec to endrec - 1 dttemp.importrow(dtsource.rows(i)) recno = recno + 1 next datagrid1.datasource = dttemp displaypageinfo() end sub private sub btnfirstpage_click(byval sender as system.object, _ byval e as system.eventargs) handles btnfirstpage.click if not checkfillbutton() then return ' check if you are already at the first page. if currentpage = 1 then messagebox.show( "you are at the first page! ") return end if currentpage = 1 recno = 0 loadpage() end sub private sub btnlastpage_click(byval sender as system.object, _ byval e as system.eventargs) handles btnlastpage.click if not checkfillbutton() then return ' check if you are already at the last page. if recno = maxrec then messagebox.show( "you are at the last page! ") return end if currentpage = pagecount recno = pagesize * (currentpage - 1) loadpage() end sub private sub displaypageinfo() txtdisplaypageno.text = "page " & currentpage.tostring & "/ " & pagecount.tostring end sub private sub btnfillgrid_click(byval sender as system.object, _ byval e as system.eventargs) handles btnfillgrid.click 'set the start and max records. pagesize = txtpagesize.text maxrec = dtsource.rows.count pagecount = maxrec \ pagesize ' adjust the page number if the last page contains a partial page. if (maxrec mod pagesize) > 0 then pagecount = pagecount + 1 end if 'initial seeings currentpage = 1 recno = 0 ' display the content of the current page. loadpage() end sub private function checkfillbutton() as boolean 'check if the user clicks the "fill grid " button. if pagesize = 0 then messagebox.show( "set the page size, and then click the " "fill grid " " button! ") checkfillbutton = false else checkfillbutton = true end if end function private sub position_changed(byval sender as object, byval e as eventargs) with bm statusbarpanel1.text = " record " & (.count.tostring()) end with end sub 请大伙给我看看是哪里代码有遗漏或不对 |
|
|
|
|