1 Replies - 1475 Views - Last Post: 12 October 2012 - 02:30 AM Rate Topic: -----

#1 hendrikbez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 20-August 08

How to get dataview columns in order that I need it to be

Posted 10 October 2012 - 04:44 AM

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

I have a datavie 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



Is This A Good Question/Topic? 0
  • +

Replies To: How to get dataview columns in order that I need it to be

#2 hendrikbez  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 40
  • Joined: 20-August 08

Re: How to get dataview columns in order that I need it to be

Posted 12 October 2012 - 02:30 AM

bump
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1