CheckListBox binding to an Excel Spreadsheet
-
Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()
-
Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()
Tazy wrote:
I am new to programming
Then why are you working on something this complex ? No-one is paying for your 'new to programming' code, are they ? If so, shame on you. If you're learning, choose something simpler to start with. You're just guessing here, and you'd do better to take a methodical approach to learning.
Tazy wrote:
'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This
Well, a MsgBox is the wrong approach to take with ASP.NET anyhow, that will kill your server in a hurry. However, I assume this is debug code. Try instead to set a breakpoint. You'll find that the item is actually a DataRow, so you need to do Items(0)("SystemName"), or whatever. In futurem don't say 'this didn't work', say 'this threw this excpetion', or 'this gave me a different result to what i hoped for, as follows... ', or 'this gave me the following compiler error. And, for the love of all that is holy, buy a book and refer to it before asking questions. That's another step towards learning, towards actually becoming a programmer. People who take those sort of steps, are the sort of people we most like to help, because it doesn't feel like smashing your head against a wall.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Good Morning All, I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks. Tazy Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0" Public Sub Retrieve_Records() Dim conn As New OleDbConnection(m_sConn2) Dim ExcelData As String Dim i As Integer conn.Open() Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn) Dim ds As DataSet = New DataSet Try da.Fill(ds) CheckedListBox1.DataSource = ds CheckedListBox1.DisplayMember = ds.Tables(0).TableName 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This Me.Refresh() Catch OleDbExceptionErr As OleDbException MsgBox(OleDbExceptionErr.Message) End Try conn.Close()
-
One error I spotted
Tazy wrote:
CheckedListBox1.DisplayMember = ds.Tables(0).TableName
should be something like
CheckedListBox1.DisplayMember = "SystemName"
(or whichever column you want to display) Hope this helpsBob Ashfield Consultants Ltd
-
Good Morning Bob, And once again Thx for your assistance. I tried your response will was given only: "System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?
This is further proof that my answer is correct. Did you try what I suggested ?
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Tazy wrote:
I am new to programming
Then why are you working on something this complex ? No-one is paying for your 'new to programming' code, are they ? If so, shame on you. If you're learning, choose something simpler to start with. You're just guessing here, and you'd do better to take a methodical approach to learning.
Tazy wrote:
'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work 'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This
Well, a MsgBox is the wrong approach to take with ASP.NET anyhow, that will kill your server in a hurry. However, I assume this is debug code. Try instead to set a breakpoint. You'll find that the item is actually a DataRow, so you need to do Items(0)("SystemName"), or whatever. In futurem don't say 'this didn't work', say 'this threw this excpetion', or 'this gave me a different result to what i hoped for, as follows... ', or 'this gave me the following compiler error. And, for the love of all that is holy, buy a book and refer to it before asking questions. That's another step towards learning, towards actually becoming a programmer. People who take those sort of steps, are the sort of people we most like to help, because it doesn't feel like smashing your head against a wall.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
No I'm new on the job and just grad. from school and this is part of a project my boss has asked me to take over. I thought this would be easier then this and would make me look good, but school has prepared me enough for this type of project. But I also don't like to give up, so I keep trying. I don't want him to think that he hired the wrong person for the job.
-
No I'm new on the job and just grad. from school and this is part of a project my boss has asked me to take over. I thought this would be easier then this and would make me look good, but school has prepared me enough for this type of project. But I also don't like to give up, so I keep trying. I don't want him to think that he hired the wrong person for the job.
OK - well, like I said, when you get an item from the items collection, it's a datarow, so you need to look up the data in the column you want to view from there. That's what the control does with the displaymember property.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Good Morning Bob, And once again Thx for your assistance. I tried your response will was given only: "System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?