Click here to Skip to main content
15,892,298 members

i got all the values of all columns in 1st column and remaining are empty, everytime i load the listview its number of rows and entries increases automatically

Zubair Lohani asked:

Open original thread
i got all the values of all columns in 1st column and remaining are empty, everytime i load the listview its number of rows and entries increases automatically ,
what should i do,

Imports System.Data.SqlClient
Imports System.IO
Imports System.Windows.Forms.TabControl
Public Class IssueWorkOrder
Inherits System.Windows.Forms.Form
Dim cn As System.Data.SqlClient.SqlConnection
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim itemcoll(100) As String
Sub connect()
cn = New System.Data.SqlClient.SqlConnection("Data Source=localhost;Initial Catalog=Fleet Maintainance;Integrated Security=True")
End Sub
VB
Sub listView2load()
       Me.ListView2.View = View.Details
       Me.ListView2.GridLines = True
       Dim conn As New SqlConnection("Data Source=localhost;Initial Catalog=Fleet Maintainance;Integrated Security=True")
       conn.Open()
       Dim clm1 As String
       Dim clm2 As String
       Dim clm3 As String
       Dim clm4 As String
       ListView2.Columns.Clear()
       Dim cmd As New SqlCommand("select * from MaintenanceTask", conn)
       cmd.CommandType = CommandType.Text
       Dim reader As SqlDataReader = cmd.ExecuteReader()
       Me.ListView2.Columns.Add("PartNumber")
       Me.ListView2.Columns.Add("Name")
       Me.ListView2.Columns.Add("QuantityUsed")
       Me.ListView2.Columns.Add("UnitCost")
       While reader.Read()
           clm1 = reader("PartNumber").ToString
           ListView2.Items.Add(clm1)
           clm2 = reader("Name").ToString
           ListView2.Items.Add(clm2)
           clm3 = reader("QuantityUsed").ToString
           ListView2.Items.Add(clm3)
           clm4 = reader("UnitCost").ToString
           ListView2.Items.Add(clm4)
       End While
       reader.Close()
       conn.Close()


   End Sub
Tags: Visual Basic (Visual Basic 10)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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