日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
講述VB.NETDataGrid實(shí)現(xiàn)主/從數(shù)據(jù)表

在向大家詳細(xì)介紹VB.NET Data Grid之前,首先讓大家了解下實(shí)現(xiàn)DataGrid2的內(nèi)容動(dòng)態(tài)更新,然后全面介紹VB.NET Data Grid。

成都創(chuàng)新互聯(lián)專注于企業(yè)全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、鄂城網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、html5、成都商城網(wǎng)站開(kāi)發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為鄂城等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。

VB.NET Data Grid實(shí)現(xiàn)主/從數(shù)據(jù)表

更有效的解決方案是使用兩個(gè)VB.NET Data Grid控件,主、從表均可見(jiàn)。對(duì)主表上某行進(jìn)行選擇,會(huì)立即引發(fā)從表內(nèi)容的改變。

建立工程,添加一個(gè)Panel控件,將其Dock屬性設(shè)置為T(mén)op;添加一個(gè)Splitter控件,Dock屬性同樣設(shè)置為T(mén)op;在窗體下部再添加一個(gè) Panel,Dock屬性為top.然后,在兩面板中各添加一個(gè)VB.NET Data Grid,其Dock屬性為Fill.

要實(shí)現(xiàn)DataGrid2的內(nèi)容動(dòng)態(tài)更新,需要對(duì)DataGrid1的CurrentCellChanged事件進(jìn)行監(jiān)聽(tīng),在接受到DataGrid1的變化消息后,加載相應(yīng)的數(shù)據(jù)。

 
 
 
  1. Imports System.Data.SqlClient  
  2. Public Class Form1  
  3. Const Connection String As String = "integrated security=sspi;initial catalog=pubs; 
  4. data source=(local)" 
  5. Private Sub Button1_Click(By Val sender As Object, 
    By Val e As System.EventArgs) Handles Button1.Click  
  6. Dim cn As New SqlConnection(Connection String)  
  7. cn.Open()  
  8. Dim ds As New Dataset  
  9. Dim GetTitlesString As String = "Select * From Titles" 
  10. Dim Titles Table As New Data Table("Titles")  
  11. ds.Tables.Add(Titles Table)  
  12. Dim da As New SqlDataAdapter(GetTitlesString, cn)  
  13. da.Fill(Titles Table)  
  14. da.Dispose()  
  15. cn.Close()  
  16. DataGrid1.DataSource = Titles Table  
  17. ’主表顯示在DataGrid1中  
  18. End Sub  
  19. Private Sub DataGrid1_CurrentCellChanged(By Val sender As Object, 
    By Val e As System.EventArgs) Handles DataGrid1.CurrentCellChanged  
  20. Dim titled As String = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0).To String  
  21. ’判斷用戶在主表中選擇了哪一行,取出它的第0列(在本例中即為title_id列)  
  22. Dim sql As String = "select * from sales where title_id=’" & titled & "’"  
  23. ’SQL命令字符串,選擇與主表中相同title_id值的從表數(shù)據(jù)  
  24. Dim cn As New SqlConnection(Connection String)  
  25. cn.Open()  
  26. Dim ds As New Dataset  
  27. Dim da As New SqlDataAdapter(sql, cn)  
  28. Dim Sales Table As New Data Table("Sales")  
  29. ds.Tables.Add(Sales Table)  
  30. da.Fill(Sales Table)  
  31. ’用選擇的從表數(shù)據(jù)填充,更新  
  32. da.Dispose()  
  33. cn.Close()  
  34. DataGrid2.DataSource = Sales Table  
  35. End Sub  
  36. End Class 

運(yùn)行程序,在主表中選擇某行,從表就會(huì)顯示出匹配的銷售信息。

利用主/從數(shù)據(jù)表模式,能在較小的編程工作量下,實(shí)現(xiàn)很好的顯示及操作效果。若要建立多表關(guān)聯(lián)的主/從視圖,或是進(jìn)行增、刪、改等操作,在此方法上進(jìn)行改進(jìn)即可。希望本文能給讀者在數(shù)據(jù)庫(kù)編程時(shí)帶來(lái)一定的啟示和幫助。

【編輯推薦】

  1. 淺談VB.NET線程構(gòu)造器
  2. 簡(jiǎn)單分析VB.NET使用線程
  3. VB.NET List(T)編寫(xiě)框架方法
  4. 簡(jiǎn)單介紹VB.NET線程同步
  5. VB.NET聲明API詳細(xì)描述

分享名稱:講述VB.NETDataGrid實(shí)現(xiàn)主/從數(shù)據(jù)表
瀏覽路徑:http://www.dlmjj.cn/article/copeosh.html