list1.additem j 意思就是把j添加至list1列表中,這是在一個for 循環(huán)中,循環(huán)了10次,添加了10次 j,即 list1 中 有10列分別為:1,3,6,10,15,21,28,36,45,55
創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營銷推廣、網(wǎng)站重做改版、惠來網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、HTML5建站、商城開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為惠來等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
下面又來了一個循環(huán), list1.removeitem 刪除列,刪除的是 list1.listcount - i ,list1.listcount 就是總列數(shù)為10,減去 i ,i 是1到4,即10-1,9-2,8-3,7-4 每減掉一次,list1.listcount 就少了一條記錄。
(注意,list1.listcount-1 是最后一條記錄)
減掉了第 9,7,5,3列
剩余為 1,3,6,15,28,45
結(jié)果為:3,15,28
'ListCount返回列表框中的項目總數(shù)
'ListCount-1是列表框中最后一個項目的索引號
'虧你提醒了,我寫錯了,上面修改了,第一個索引為0,最后一個為9.
'也就是,問題所問的第二列的索引為1,第四列的索引為3...
兄弟呀這個這么簡單 用這個語法吧 MsgBox(TextBox1.Text.Length)‘就是用消息窗口顯示幾個字符
遍歷所有子窗體,檢查其狀態(tài)。
記得表單有一個集合對象controls,里面包含它所轄的所有子控件。在判斷控件類型是否form后,若是則判斷它是否Visibled,符合條件的都做相應(yīng)變化。這樣處理局限時較小,代碼可以通用,一勞永逸,好處自不必言。
當(dāng)然能,把你不分頁的程序貼出來,我給你修改嘛。
主要就是利用rs.PageSize等實現(xiàn),在你程序的下面語句:
rs.open sqlc,conn,1,1
之后,添加下面的代碼可以控制顯示的記錄范圍:
rs.PageSize = 10 'pagesize屬性指定了每頁要顯示的記錄條數(shù)
rs.AbsolutePage = Page '把頁碼賦給absolutepage屬性從而知當(dāng)前頁的首條記錄號
上的PAGE是調(diào)用是帶過來的參數(shù),沒有參數(shù)時指定為1,表示顯示第一頁。
script type="text/javascript" src="" /script
script type="text/javascript" src="" /script
有兩個表order(orderid,ordername,totalprice), orderdetail(orderid,productid,productname,price) 已經(jīng)建立一對多
關(guān)聯(lián)(orderid). 用VB.NET建立一個窗體, 用于主表和明細(xì)表的數(shù)據(jù)錄入及更新.
在窗體上增加兩個sqldataadapter,分別選擇order和orderdetail表, 并生成數(shù)據(jù)集,在DATASET中建立關(guān)聯(lián)(orderid) 主表中:ORDERID,ORDERNAME 綁定在兩個TEXTBOX文本框中,用于接受用戶的輸入,totalprice接受明細(xì)表中price
的匯總值.
明細(xì)表綁定到一個DATAGRID控件, datasource:dsorder; datamember:order.orderorderdetail建立的關(guān)聯(lián)名稱
問題: 在主表中新增一個記錄,用戶錄入orderid和ordername后,進(jìn)入明細(xì)表的錄入,用戶錄入productid, productname, price后,提示 “明細(xì)orderID列不允許空值,要更正該值嗎?” 是什么原因?
用于連接主表的明細(xì)orderID如果輸入跟主表一樣的orderID時提示“ForeignKeyconstraint 要求在交叉表中存在子鍵值。要更正該值嗎?”
只有錄入主表中的orderid和ordername后, 先更新主表數(shù)據(jù)源,才可以編輯更新明細(xì)表,這是為什么? 請問,有沒有其他更好的方法, 實現(xiàn)主表和明細(xì)表的新增記錄同時更新呢? 謝謝關(guān)照! 網(wǎng)友:方宇 回復(fù):
附部分源代碼:
Public Class fmOrders
Inherits System.Windows.Forms.Form
Dim WithEvents dtOrderDetails As New DataTable()
Dim BmOrders As BindingManagerBase
Dim BmOrderDetails As BindingManagerBase
Dim OrderDetailsHasChange As Boolean
Dim orderid As DataColumn
dim ordername as datacolumn
Dim SubTotal As DataColumn Private Sub bnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnFirst.Click
BmOrders.Position = 0
End Sub
Private Sub bnPrior_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnPrior.Click
BmOrders.Position -= 1
End Sub
Private Sub bnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnNext.Click
BmOrders.Position += 1
End Sub
Private Sub bnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnLast.Click
BmOrders.Position = BmOrders.Count - 1
End Sub Private Sub bnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnAdd.Click
Try
BmOrders.EndCurrentEdit()
BmOrders.AddNew()
Catch err As System.SystemException
MessageBox.Show(err.ToString)
End Try
End Sub
Private Sub bnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnLoad.Click
FillData()
End Sub Private Sub bnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bnUpdate.Click
Dim dsTestOrdersChange As DataSet BmOrderDetails.EndCurrentEdit()
BmOrders.EndCurrentEdit()
If Not dsTestOrders.HasChanges(DataRowState.Deleted) Then
Try
daOrders.Update(dsTestOrders, "Orders")
daOrderDetails.Update(dsTestOrders, "OrderDetails")
dsTestOrders.AcceptChanges()
Catch err As System.SystemException
dsTestOrders.RejectChanges()
MessageBox.Show(err.ToString)
Throw
End Try
Else
Try
daOrderDetails.Update(dsTestOrders, "OrderDetails")
daOrders.Update(dsTestOrders, "Orders")
dsTestOrders.AcceptChanges()
Catch err As System.SystemException
dsTestOrders.RejectChanges()
MessageBox.Show(err.ToString)
Throw
End Try
End If
End Sub Private Sub fmOrders_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillData()
dtOrderDetails = dsTestOrders.Tables("OrderDetails")
BmOrders = Me.BindingContext(dsTestOrders, "Orders")
BmOrderDetails = Me.BindingContext(dsTestOrders, "Orders.OrdersOrderDetails")
OrderDetailsHasChange = True
SubTotal = dsTestOrders.Tables("Orders").Columns("SubTotal")
SubTotal.DefaultValue = 0
Price = dsTestOrders.Tables("OrderDetails").Columns("Price")
Price.DefaultValue = 0
End Sub Private Sub FillData()
dsTestOrders.EnforceConstraints = False
daOrders.Fill(dsTestOrders)
daOrderDetails.Fill(dsTestOrders)
dsTestOrders.EnforceConstraints = True
End Sub
Private Sub dtOrderDetails_ColumnChanged(ByVal sender As Object, ByVal e As System.Data.DataColumnChangeEventArgs) _
Handles dtOrderDetails.ColumnChanged Dim drOrders As DataRow
Dim drOrderDetails As DataRow
Dim iSubTotal As Integer
Try
If OrderDetailsHasChange Then
OrderDetailsHasChange = False
drOrders = dsTestOrders.Tables("Orders").Rows(BmOrders.Position)
iSubTotal = 0
For Each drOrderDetails In drOrders.GetChildRows("OrdersOrderDetails")
iSubTotal = iSubTotal + drOrderDetails("price")
Next
drOrders.BeginEdit()
drOrders("SubTotal") = iSubTotal
drOrders.EndEdit()
End If
Finally
OrderDetailsHasChange = True
End Try
End Sub Private Sub bndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bndelete.Click
If BmOrders.Count 0 Then
BmOrders.RemoveAt(BmOrders.Position)
End If
End Sub Private Sub bncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bncancel.Click
BmOrders.CancelCurrentEdit() End Sub
End Class script type="text/javascript" src="" /script
script type="text/javascript" src="" /script
Dim da As New DataTable
Dim myda As OleDb.OleDbDataAdapter("SELECT * FROM 表“, oconnection)
myda.Fill(da)
姓名=da.Rows(0)(0) ‘張三
姓名=da.Rows(1)(0) ‘李四
姓名=da.Rows(2)(0) ‘王五
姓名=da.Rows(3)(0) ‘趙六
姓名=da.Rows(4)(0) ‘劉琦
這個不一定要用數(shù)組,直接用table就可以操作了。