如何获取dataview列以便我需要它

如何获取dataview列以便我需要它

本文介绍了如何获取dataview列以便我需要它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个程序,我想做点什么.但无法正常工作.

我也有一个数据视图,我需要它在数据视图中显示,当我按下按钮1时,它应该为我提供所有房间,当我按下按钮2时,它应该保持原样,但现在带有窗格编号同样,依此类推,现在发生的事情是,当我按下任何按钮时,它只会按顺序执行该按钮的信息.我需要有关如何执行此操作的帮助.

I have this program and I want to do something. but can not get it to worked.

I have a dataview in it also, I need it to show in the dataview on when I press button1 it should give me all the the rooms in order, when I press button 2 it should keep room like it is, but now with pod number also, and so on, what is happening now, when I press any button, it only do that button info in order. I need help on how to do this.

Imports System.Data.OleDb

Public Class ServerRoom

    WithEvents bsExcelData As New BindingSource

    Private Sub ServerRoom_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New DataTable
        Using cn As New OleDb.OleDbConnection
            Dim Builder As New OleDbConnectionStringBuilder With {.DataSource = IO.Path.Combine(Application.StartupPath, "Serverroomlayout.xls"), .Provider = "Microsoft.ACE.OLEDB.12.0"}
            Builder.Add("Extended Properties", "Excel 12.0; IMEX=1;HDR=No;")
            cn.ConnectionString = Builder.ConnectionString
            cn.Open()
            Using cmd As OleDbCommand = New OleDbCommand With {.Connection = cn}
                cmd.CommandText = "SELECT TOP 516 F1 As ServerName, F2 As Room, F3 As Row, F4 as Rack, F5 as Pod, F6 as Vanaf, F7 as na, F9 as Ipaddress, F10 as Vlan, F11 as Model, F12 as Type, F13 as Operating_System, F14 as Application, F15 as app_owner, F16 as Ram FROM [EveryThing$]"
                Dim dr As System.Data.IDataReader = cmd.ExecuteReader
                dt.Load(dr)
                LstServerName.DisplayMember = "ServerName"
                LstServerName.DataSource = dt
                txtRoom.DataBindings.Add("Text", dt, "Room")
                TxtRow.DataBindings.Add("Text", dt, "Row")
                txtRack.DataBindings.Add("Text", dt, "Rack")
                txtPod.DataBindings.Add("Text", dt, "Pod")
                txtFrom.DataBindings.Add("Text", dt, "vanaf")
                txtTo.DataBindings.Add("Text", dt, "na")
                TxtIPAddress.DataBindings.Add("Text", dt, "Ipaddress")
                txtVlan.DataBindings.Add("Text", dt, "Vlan")
                txtModel.DataBindings.Add("Text", dt, "Model")
                txtType.DataBindings.Add("Text", dt, "Type")
                TxtOS.DataBindings.Add("Text", dt, "Operating_System")
                TxtApp.DataBindings.Add("Text", dt, "Application")
                TxtAppOwner.DataBindings.Add("Text", dt, "app_owner")
                TxtRam.DataBindings.Add("Text", dt, "Ram")
            End Using
        End Using
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using cn As New OleDb.OleDbConnection
            cn.SetExcelConnectionString("C:\Do_it\ServerRoomLayout.xls", UseHeader.Yes, ExcelImex.TryScan)
            Console.WriteLine(cn.ConnectionString)
            cn.Open()
            Using cmd As New OleDb.OleDbCommand With
                {
                    .Connection = cn,
                    .CommandText =
                    '<sql>
                    SELECT
                        Room,
                        [POD #] As POD,
                        [Server Name] As Server,
                        [Row #] As [RowNo],
                        [Rack #] As Rack,
                        [From] As Origin,
                        [to] As Dest,
                        [How many rows in rack] As RowCount,
                        [IP Address] As IPAddress,
                        VLAN,
                        Model,
                        [Type],
                        [Operating System] As OS,
                        Application,
                        [App# Owner] As AppNoOwner,
                        Ram
                    FROM
                        [EveryThing$]
                    WHERE [Room] IS NOT NULL
               ' </sql>.Value
                }
                Dim dt As New DataTable
                dt.Load(cmd.ExecuteReader)
                bsExcelData.DataSource = dt
                DataGridView1.DataSource = bsExcelData
            End Using
        End Using
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        bsExcelData.Filter = "Pod='1'"
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        bsExcelData.Filter = "RowNo='A'"
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        bsExcelData.Filter = "Rack='1'"
    End Sub
    Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
        Application.Exit()
    End Sub
End Class

推荐答案



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

bsExcelData.Filter = "Pod='1'"
DataGridView1.DataSource = bsExcelData
DataGridView1.DataBind()
End Sub


这篇关于如何获取dataview列以便我需要它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:30