Click here to Skip to main content
15,891,698 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.
VB
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
Posted
Updated 10-Oct-12 2:07am
v2

Try and rebind the gridview after the filter is preformed.

VB
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
 
Share this answer
 
I am getting this error

databind is not a member of 'System.windows.forms.datagridview' with this

C#
DataGridView1.DataBind()


I try ti rem it, but it then gives me the same info as before
 
Share this answer
 
v2
bump! bump! bumpbump! bump! bump

any help!!!!!! Please.......
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900