日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

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

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

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

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

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

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

要實現(xiàn)DataGrid2的內(nèi)容動態(tài)更新,需要對DataGrid1的CurrentCellChanged事件進行監(jiān)聽,在接受到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 

運行程序,在主表中選擇某行,從表就會顯示出匹配的銷售信息。

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

【編輯推薦】

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

當(dāng)前標(biāo)題:講述VB.NETDataGrid實現(xiàn)主/從數(shù)據(jù)表
文章地址:http://www.5511xx.com/article/copeosh.html