K Feening
asked on
Vb.net Listview
HI Experts
I have an SQL statement
e.g
me.listview.Columns.Add(SQ L.Field(0) , 100, HorozontalAlignment.left)
me.listview.Columns.Add(SQ L.Field(1) , 100, HorozontalAlignment.left)
Thanks
I have an SQL statement
SELECT Name, Address, Suburb, State FROM ADDRESSES
Is there a way to add the SQL Select Field names to a Listviewe.g
me.listview.Columns.Add(SQ
me.listview.Columns.Add(SQ
Thanks
ASKER
In SQL server you run a script and it adds the Column headers in VB when the user can change the SQL from
To
How do you get the Column Header Number, Name etc and number of columns 6
SELECT Name, Address, Suburb, State FROM ADDRESSES
To
SELECT Number, Name, Address, Suburb, State, Postcode FROM ADDRESSES
How do you get the Column Header Number, Name etc and number of columns 6
I think I'm not clear enough in my question above.
what I mean is:
>>SQL.Field(0)
what is this SQL object?
To answer your other questions we need to understand what is this object.
what I mean is:
>>SQL.Field(0)
what is this SQL object?
To answer your other questions we need to understand what is this object.
Hi Kevinfeening,
To bind listview with sql result, you'll have to take the table returned from sql in a datatable and bind your listview with that datatable.
Try below code by passing your connection string, your sql query and your listview.
To bind listview with sql result, you'll have to take the table returned from sql in a datatable and bind your listview with that datatable.
Try below code by passing your connection string, your sql query and your listview.
Dim constr As String = "Put your connection string here"
Dim ds As New DataSet
Dim con As New SqlClient.SqlConnection(constr)
con.Open()
Dim sqladap As New SqlClient.SqlDataAdapter("SELECT Number, Name, Address, Suburb, State, Postcode FROM ADDRESSES ", con)
sqladap.Fill(ds)
For i As Integer = 0 To ds.Tables(0).Columns.Count – 1
ListView1.Columns.Add(ds.Tables(0).Columns(i).ToString())
Next
For i As Integer = 0 To ds.Tables(0).Rows.Count – 1
Dim listRow As New ListViewItem
listRow.Text = ds.Tables(0).Rows(i)(0).ToString()
For j As Integer = 1 To ds.Tables(0).Columns.Count – 1
listRow.SubItems.Add(ds.Tables(0).Rows(i)(j).ToString())
Next
ListView1.Items.Add(listRow)
Next
ASKER
No it was a example of what I thought could be done no such thing as SQL.Field(0)
its a plain SQL SELECT statement which runs in 2008 Server and I need to get the heading when running in VB.net
its a plain SQL SELECT statement which runs in 2008 Server and I need to get the heading when running in VB.net
using Dim Reader as Data.IDaterReader = DataConnector.GetReader(SQL,Nothing)
Do While reader.read = true
loop
Here columns in datatable will be same as what you are getting from your sql query. You can use column name of datatable in your list view.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Simple and worked
Others more complicated but worked
Thanks All
Others more complicated but worked
Thanks All
quick guess, you probably can try: SQL.Field(0).Name ?