Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

i have an error to call module to my forms "Value of type 'Integer' cannot be converted to 'System.Data.DataTable'".

i have a module to fill data in the listview,

VB
Module ModProcedure
      Dim xsize As Integer
      'load data in the listview
      Public Sub FillListView(ByVal sqlData As DataTable, ByVal lvList As ListView, ByVal imageID As Integer)
            Dim i As Integer
            Dim j As Integer
            'lvList.Refresh()
            lvList.Clear()
            For i = 0 To sqlData.Columns.Count - 1
                  lvList.Columns.Add(sqlData.Columns(i).ColumnName)
            Next i
 
            For i = 0 To sqlData.Rows.Count - 1
                  lvList.Items.Add(sqlData.Rows(i).Item(0), imageID)
                  For j = 1 To sqlData.Columns.Count - 1
                        If Not IsDBNull(sqlData.Rows(i).Item(j)) Then
                              lvList.Items(i).SubItems.Add(sqlData.Rows(i).Item(j))
                        Else
                              lvList.Items(i).SubItems.Add("")
                        End If
                  Next j
            Next i
 
            For i = 0 To sqlData.Columns.Count - 1
                  xsize = lvList.Width / sqlData.Columns.Count - 8
                  'MsgBox(xsize)
                  'If xsize > 1440 Then
                  lvList.Columns(i).Width = xsize
                  'Else
                  '   lvList.Columns(i).Width = 2000
                  'End If
                  'lvList.Columns(i).AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize)
            Next i
      End Sub---

i used to call this function to my form but i am facing problem to call data table as below

VB
Private Sub FrmWHMaster_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
         
            Dim myCn As New dbconnection
            Dim cnn As New SqlClient.SqlConnection(myCn.Getdbconn)
            Dim sqlStr As String
            ' Try
            cnn.Open()
 
            sqlStr = "select * from userMaster"
 

            Dim cmd1 As New SqlClient.SqlCommand(sqlStr, cnn)
            cmd1.CommandType = CommandType.Text
          FillListView(cmd1.ExecuteNonQuery, IstCurrentload, 0)
 
            cnn.Close()
 
      End Sub


This is the area i am getting error?please advice.
VB
FillListView(cmd1.ExecuteNonQuery, IstCurrentload, 0)


Thanks,
Ali
Posted
Updated 22-Jan-12 22:35pm
v2

ExecuteNonQuery always returns a single value, the number of records affected. If you want to use a DataTable, then you need to use a DataAdapter instead, and Fill the DataTable from that.

[edit]Database --> DataTable - OriginalGriff[/edit]
 
Share this answer
 
v2
Thank you .. i changed my code to Dataadapter, it works

Dim da As New SqlClient.SqlDataAdapter(sqlStr, con)
Dim dt = New DataTable
da.Fill(dt)
sqlStr = da.Fill(dt)
FillListView(ExecuteSQLQuery(sqlStr), IstCurrentload, 0)
 
Share this answer
 

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



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