Click here to Skip to main content
12,511,538 members (50,980 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
HI, I am new to vb.net. Can someone teach me how to show data from the sql database to the vb.net listview.

For example:
My db has a Data column, and i would like to have only the previous 20 days are showed on the listview.

If someone can provide me some source code that would be alot helpfull.

Thank you very much.
Posted 15-Apr-10 19:09pm
Updated 1-Mar-16 10:52am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Imports System.Data.SqlClient
Public Class Form1
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim itemcoll(100) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListView1.View = View.Details
Me.ListView1.GridLines = True
conn = New SqlConnection("Data Source=SQLEXPRESS;Initial Catalog=Northwind;Persist Security Info=True;User ID=id;Password=pass")
Dim strQ As String = String.Empty
strQ = "SELECT * FROM Northwind.dbo.Products"
cmd = New SqlCommand(strQ, conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet
da.Fill(ds, "Table")
Dim i As Integer = 0
Dim j As Integer = 0
' adding the columns in ListView
For i = 0 To ds.Tables(0).Columns.Count - 1
Me.ListView1.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
Next
'Now adding the Items in Listview
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
Next
Dim lvi As New ListViewItem(itemcoll)
Me.ListView1.Items.Add(lvi)
Next
End Sub
End Class
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

it is ok if it is vulnerable at the moment.
I am just trying to make a program for personal use. btw i edited some code and still cant make it run.



 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
 

        mysqlconn = New MySqlConnection
        mysqlconn.ConnectionString = "server=localhost;user=root;password=root;database=database"
        Dim Reader As MySqlDataReader
 
        Dim strQ As String = String.Empty
        Dim conn As MySqlConnection
            Dim cmd As MySqlCommand
            Dim da As MySqlDataAdapter
            Dim ds As DataSet
            Dim itemcoll(100) As String
            strQ = "SELECT * FROM database.benta where customerID = '" & txtnos.Text "'"
            cmd = New SqlCommand(strQ, conn)
        da = New SqlDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, "Table")
            Dim i As Integer = 0
            Dim j As Integer = 0
            ' adding the columns in ListView
            For i = 0 To ds.Tables(0).Columns.Count - 1
                Me.lva.Columns.Add(ds.Tables(0).Columns(i).ColumnName.ToString())
            Next
            'Now adding the Items in Listview
            For i = 0 To ds.Tables(0).Rows.Count - 1
                For j = 0 To ds.Tables(0).Columns.Count - 1
                    itemcoll(j) = ds.Tables(0).Rows(i)(j).ToString()
                Next
                Dim lvi As New ListViewItem(itemcoll)
                Me.lva.Items.Add(lvi)
            Next
End Sub
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160929.1 | Last Updated 1 Mar 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100