Originally posted by: dicky
After I change from SqlDataReader to OleDbDataReader in GetCustomers(), myData is not work.
Pls advise.
'OleDbDataReader
Private Sub GetCustomers()
Dim myCon As System.Data.OleDb.OleDbConnection
Dim myCmd As System.Data.OleDb.OleDbCommand = New OleDbCommand("SELECT * FROM Customers")
Dim myData As System.Data.OleDb.OleDbDataReader
Dim itmListItem As ListViewItem
Dim lvhHelper As ListViewData = New ListViewData()
'myCon = New SqlConnection("Data Source=DevBox;Initial Catalog=Northwind;User ID=sa;Pwd=hi")
myCon = New System.Data.OleDb.OleDbConnection("Provider = SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;User ID=sa")
Try
myCon.Open()
myCmd.Connection = myCon
myData = myCmd.ExecuteReader
lvhHelper.FillListView(lvwCustomers, myData)
myCon.Close()
Catch eSql As System.Data.OleDb.OleDbException
MessageBox.Show(eSql.ToString)
End Try
End Sub
'SqlDataReader
Private Sub GetCustomers()
Dim myCon As SqlConnection
Dim sqlCmd As SqlCommand = New SqlCommand("SELECT * FROM Customers")
Dim myData As SqlDataReader
Dim itmListItem As ListViewItem
Dim lvhHelper As ListViewData = New ListViewData()
myCon = New SqlConnection("Data Source=localhost;Initial Catalog=Northwind;User ID=sa")
Try
myCon.Open()
sqlCmd.Connection = myCon
myData = sqlCmd.ExecuteReader
lvhHelper.FillListView(lvwCustomers, myData)
myCon.Close()
Catch eSql As System.Data.SqlClient.SqlException
MessageBox.Show(eSql.ToString)
End Try
End Sub
Originally posted by: Homeboy
The title does not match dude ! make it clear...
ReplyOriginally posted by: Atanasia
Hi!
I have test this ListView application but it never work.
I get error message: An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll
Additional information: Specified cast is not valid.
Row: itmListItem.SubItems.Add(myData.GetString(shtCntr))
Why?
Reply
Originally posted by: Jes�s
change the property
View = Details
Originally posted by: Anand
How can we strikeout the some selected list items in a list view? We can use checkboxes property to distinigh the selected list items, I would like to show that selected items as Striked out.
Can any one help me?
Thanks,
Hi,
Anand
Originally posted by: VB Expert
So if your database is filled completely with text you're okay, add a number field (or any other type of field) and your cute little program chokes and vomits.
ReplyOriginally posted by: VBNewbie
Well, the reason I was using DataViews in the first place was to take advantage of the .RowFilter property - and as it turns out, DataViews do not automatically enforce the .RowFilter except when you're working with a DataGrid (at least they don't work with ListViews, which is unfortunate for me). What I ended up doing was a comparitively clunky if/then:
If DSRow.ItemArray(2) = strCriteria Then
Oh well.
Heh, later I notice that the DataTable object has a handy dandy .Select method. Double duh.
Reply
Originally posted by: VBNewbie
I'm working on a program where the data is local
(delimited text actually) and it's quite small, so it seems
simpler to just work with the data in memory in a DataSet.
I also wanted to use the ListView control (DataGrid does
wierd things that I don't want) and I applied Mr.
Waiblinger's method to DataSets connected with ListViews.
Thanks to Bill for getting me started, or I wouldn't likely
have figured out how! Here's the code for how I did it,
for a simple 1-column table and a table with a variable
number of columns, in all its clumsy glory:
Private Sub InitializeListViews()
Dim lvwColumn As ColumnHeader
Dim itmListItem As ListViewItem
Dim strTest As String
Dim shtCntr As Short
Dim DSRow As DataRow
lvwListView1.Clear()
lvwColumn = New ColumnHeader()
'Create Column Header - only one column to add for this table
'so no need to loop
lvwColumn.Text = dvwDataView1.Table.Columns.Item(0).ColumnName.ToString
lvwListView1.Columns.Add(lvwColumn)
'Populate the listview items
For Each DSRow In dvwDataView1.Table.Rows
itmListItem = New ListViewItem()
itmListItem.Text = DSRow.ItemArray(0)
lvwListView1.Items.Add(itmListItem)
Next
'Now for the more complex table
lvwListView2.Clear()
'Loop through the columns in dvwDataView2 and make a column
'header for each item
For shtCntr = 0 To dvwDataView2.Table.Columns.Count - 1
lvwColumn = New ColumnHeader()
'Create Column Header
lvwColumn.Text = dvwDataView2.Table.Columns.Item(shtCntr).ColumnName.ToString
lvwListView2.Columns.Add(lvwColumn)
Next
'Populate the listview items
For Each DSRow In dvwDataView2.Table.Rows
itmListItem = New ListViewItem()
itmListItem.Text = DSRow.ItemArray(0)
lvwListView2.Items.Add(itmListItem)
'In my example I didn't care if the value was null
'because I was using a default value of ""
'Might be wise to figure out how to test for null!
For shtCntr = 1 To DSRow.ItemArray.GetUpperBound(0)
itmListItem.SubItems.Add(DSRow.ItemArray.GetValue(shtCntr))
Next
Next
Reply
Originally posted by: Jim DuRocher
Any tips would be appreciated!
Here is a sample of the code I'm using:
Dim lvwColumn As ColumnHeader
Dim shtCntr As Short
lvProperty.Clear()
For shtCntr = 1 To 3
lvProperty.Items.Add(itmListItem)
Your listview example was great, thanks for posting it. Do you have to do anything special to enable to column headers? When I try to add columns I cannot see the column headers. Also, the only column of data that appears is the first one. All my subitems are not diplayed.
Dim itmListItem As ListViewItem
For shtCntr = 0 To 3
lvwColumn = New ColumnHeader()
lvwColumn.Text = "column" & shtCntr
lvproperty.Columns.Add(lvwColumn)
shtCntr = shtCntr + 1
Next
Dim shtCntr2 = 0
Do While shtCntr2 < 3
itmListItem = New ListViewItem()
itmListItem.Text = "jim" & shtCntr2
itmListItem.SubItems.Add("subitem" & shtCntr)
shtCntr = shtCntr + 1
Next shtCntr
shtCntr2 = shtCntr2 + 1
Loop
Originally posted by: Prashant Sawant
Data Connection
-- General Declaration
Dim CN as new ADODB.connection
-- In Form Load
-- For Database Connection
Dim Connstr as string
-- For Recordset
Connstr = "SELECT * FROM PERSONAL"
Kindly Advice
I have knowledge of vb6. In VB6
Dim Rs as new ADODB.resultset
cn.connet = "dsn=ghfcl;uid=ghfcl;pwd=ghfcl;"
RS.OPEN Connstr, cn, adopenstatic
But in vb.net How Connect Database and Open Recordset
Prashant