0
Dim sqlConString As String = "Server=localhost\TESTE;Database=tempTest;User Id=sa;Password=123"
Try
Using con = New SqlConnection(sqlConString)
con.Open()
Using cmd = con.CreateCommand
'' Para filtrar
cmd.CommandText = "SELECT * FROM Clientes where NIF LIKE '" + TextBox1.Text + "%'"
cmd.CommandText = "select * from Clientes"
Using reader = cmd.ExecuteReader
Dim counter As Int32 = 0
While reader.Read
ListView1.Items.Add(reader.GetString(reader.GetOrdinal("NIF")), counter)
counter = counter + 1
ListView1.Items.Add(reader.GetString(reader.GetOrdinal("Nome")), counter)
counter = counter + 1
ListView1.Items.Add(reader.GetString(reader.GetOrdinal("Telefone")), counter)
counter = counter + 1
''MsgBox(reader.GetString(reader.GetOrdinal("NIF")))
End While
End Using
End Using
End Using
Catch ex As Exception
MsgBox(ex.ToString())
End Try
I want you to be by every table like this https://imgur.com/a/qGAdl
So you will hardly get help from anyone, edit and put the code correctly and explain your question better!
– IdkWhy
Your question is confused... this code is not VB6 (.NET maybe?)
– NilsonUehara
This is VB my doubt is in each of the Listview1.item.Add I want to put by table for example the "NIF" I want it to be in the first column of the table under the NIF and so succinctly
– Megaluk
That’s how I found out
– Megaluk
Dim item As New ListViewItem(reader.GetString(reader.GetOrdinal("NIF")))
 item.SubItems.Add(reader.GetString(reader.GetOrdinal("Nome")))
 item.SubItems.Add(reader.GetString(reader.GetOrdinal("Contacto"))) Listview1.Items.Add(item)
– Megaluk
Why are you carrying the property
CommandText
twice? Check out this article here: https://mobile.codeguru.com/vb/controls/vbnet_controls/listview/article.php/c3979/How-to-Fill-a-ListView-with-any-ADONet-Dataset.htm.– Pedro Gaspar
You really need to use the
ListView
? If you used oneDataGridView
instead, you could upload a Dataset instead of a Datareader and play it straight to the propertyDataGridView.DataSource
, that he would already create the columns and rows. Of course you would have to change your query to return only the 3 columns you want, and in the order you want, such as:SELECT NIF, Nome, Telefone FROM Clientes
.– Pedro Gaspar