Loading

HELP TO POPULATE LIST VIEW WITH DATA FROM MYSQL

2 posts / 0 new
Last post
Offline
Joined: 11/11/2009
HELP TO POPULATE LIST VIEW WITH DATA FROM MYSQL

Please may you help me VB.NET What i want to do,Is just to display data from mysql into listview named lvList.But the problem I'm getting is that when i use the code bellow it display only Fullname horizontally next record in the next collumn without sex filed.
But the things i want is to be able to display Fullname and sex one record after another i.e next record to be in the next row not collumn with Fullname and Sex,Sex in the next collumn
Here in the code I'm Using;
Imports System
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.OleDb

Public Class FrmModify
Private pConn As OdbcConnection
Private pCommand As OdbcCommand
Dim ds1, ds2, ds3 As New DataSet
Public gConnstr As String
Private pDataAdapter As OdbcDataAdapter
Private ans As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
gConnstr = "DRIVER={" + "MySQL ODBC 3.51 Driver" _
+ "};SERVER=" + "localhost" _
+ ";UID=" + "root" _
+ ";PWD=" + "admin" _
+ ";DATABASE=" + "pccb_db" _
+ ";Max Pool Size=50" _
+ ";Min Pool Size=5" _
+ "Pooling=True" _
+ ";OPTION=3"

pConn = New OdbcConnection()
pConn.ConnectionString = Me.gConnstr
pCommand = New OdbcCommand()
pDataAdapter = New OdbcDataAdapter()

Dim mDataTable As New DataTable()
pCommand.Connection = pConn
pCommand.CommandText = "SELECT FName, Sex FROM Staff_tbl ORDER BY FName ASC"
pDataAdapter.SelectCommand = pCommand
pDataAdapter.Fill(mDataTable)

Dim lvwItem As ListViewItem
lvList.Clear()

For i As Integer = 0 To mDataTable.Rows.Count - 1

lvwItem = New ListViewItem
lvwItem.Text = mDataTable.Rows(i).Item("FName").ToString

lvwItem.SubItems.Add(mDataTable.Rows(i).Item("Sex").ToString)

lvList.Items.Add(lvwItem)

Next i
End Sub

admin's picture
Offline
Joined: 11/14/2008
re: HELP TO POPULATE LIST VIEW WITH DATA FROM MYSQL

Pages

Add new comment

Filtered HTML

  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.