Click here to Skip to main content
15,063,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application built by someone else that is returning results from a socket call when the end user types in a little product info, and hits submit. The application returns the results, but it sometimes displays the results twice. For example, if I click submit on the application to do a search for a product, it may come back with the correct one, two, or three records (as there could be results from 1-3 locations), or it may repeat all those results twice. (Ie.: if there were two records returned, it might simply display the info from the two records, or it may display the results from the two records in the first two rows of the , and then repeat rows 1 & 2 in rows 3 & 4.) Continuing to click submit on that page will (it appears randomly) change the resulting displayed data - cycling between one set of results and two.

I've included the bit of code I think is involved. I inherited this code, and am trying to make it work, but I'm new to this type of application and only intermediate at best in asp.net. Thank-you in advance to anyone who can shed some light!!

I hope this is clear enough..

VB
Protected Sub displayTableOne(ByVal records() As String)

    Dim dt As New DataTable()
    Dim values() As String = {""}
    Dim i As Integer = 0

    Try

        Dim Row() As String = {"Company", "Piece", "Description", _
        "Location", "Available", "Purchased", "Ship Date"}

        'Create the columns
        Dim column1 As New DataColumn("Company", GetType(String))
        Dim column2 As New DataColumn("Piece", GetType(String))
        Dim column3 As New DataColumn("Description", GetType(String))
        Dim column4 As New DataColumn("Location", GetType(String))
        Dim column5 As New DataColumn("Available", GetType(String))
        Dim column6 As New DataColumn("Purchased", GetType(String))
        Dim column7 As New DataColumn("Ship Date", GetType(String))


        dt.Columns.Add(column1)
        dt.Columns.Add(column2)
        dt.Columns.Add(column3)
        dt.Columns.Add(column4)
        dt.Columns.Add(column5)
        dt.Columns.Add(column6)
        dt.Columns.Add(column7)


        If (records.Length > 1) Then
            For i = 0 To records.Length - 2 Step 1

                values = Split(records(i), "|")
                Dim l As Integer = 0
                Dim dr As DataRow
                dr = dt.NewRow()

                If values(0) = "05" Then

                    If (values.Length > 4) Then
                        dr(Row(0)) = values(1)
                        dr(Row(1)) = values(2)
                        dr(Row(2)) = values(13)
                        dr(Row(3)) = values(17)
                        dr(Row(4)) = values(7)
                        dr(Row(5)) = values(15)
                        dr(Row(6)) = values(16)

                    End If

                    dt.Rows.Add(dr)

                End If
            Next

            If values(23) = "Error" Then
                invalidMessage()

            Else
                'Bind the DataTable to the DataGrid
                Table1.Visible = True
                Table1.DataSource = dt
                Table1.DataBind()
            End If
        End If
    Catch ex As Exception
        invalidMessage()
    Finally
        Array.Clear(records, 0, records.Length)
        Array.Clear(values, 0, values.Length)

    End Try

End Sub


If I run this on localhost, their is no duplication of data, but on the site there is. Does that help to give people an idea of what may be going on?
Posted
Updated 11-Oct-11 8:28am
v2
Comments
Marc A. Brown 11-Oct-11 14:52pm
   
Have you examined the String array (records()) you're passing to this function? If the data is wrong there, then the code you've provided won't help in resolving the problem.
Blue Jays Baseball Fan 11-Oct-11 14:57pm
   
yeah, the data that gets fed in is consistent - I can hit 'go' and the same data is called each time, and the same data (and numbers of lines of data) are returned and.. well mangled a bit.
Simon_Whale 11-Oct-11 16:07pm
   
I don't think your problem is there I would suggest you have a detailed look at what creates the record() array
Blue Jays Baseball Fan 17-Oct-11 14:03pm
   
Hi Simon. Thanks for looking at this for me.

Yeah, something doesn't add up. This is what is in place for the records() array.. Does this look broken/fallible to you?

Protected Sub displayData(ByVal returnData As String)

Dim records() As String = {""}
Dim i As Integer = 0

records = Split(returnData, vbLf, , CompareMethod.Binary)

If records.Length > 3 Then
displayTableOne(records)
End If


Array.Clear(records, 0, records.Length)


End Sub

Thanks!

1 solution

Hi,

See my coding if could help. I thing this should be the best approach to do...

   Imports System.Data.SqlClient
Imports System.Data

<serializable()> Public Class Product
#Region "Declared private variables"
    ' You may customized the type of field here..
    ' This is just a sample base on your code defination...
    Private _company As String
    Private _piece As String
    Private _description As String
    Private _location As String
    Private _available As String
    Private _purchased As String
    Private _shipDate As String
#End Region

#Region "Create a Public properties"
    Public Property Company() As String
        Get
            Return _company
        End Get
        Set(ByVal value As String)
            _company = value
        End Set
    End Property
    Public Property Piece() As String
        Get
            Return _piece
        End Get
        Set(ByVal value As String)
            _piece = value
        End Set
    End Property
    Public Property Description() As String
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property
    Public Property Location() As String
        Get
            Return _location
        End Get
        Set(ByVal value As String)
            _location = value
        End Set
    End Property
    Public Property Available() As String
        Get
            Return _available
        End Get
        Set(ByVal value As String)
            _available = value
        End Set
    End Property
    Public Property Purchased() As String
        Get
            Return _purchased
        End Get
        Set(ByVal value As String)
            _purchased = value
        End Set
    End Property
    Public Property ShipDate() As String
        Get
            Return _shipDate
        End Get
        Set(ByVal value As String)
            _shipDate = value
        End Set
    End Property
#End Region
#Region "Create a Constructor without parameters"
    Public Sub New()
    End Sub
#End Region
End Class

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
        Dim lstProduct As New List(Of Product)
        lstProduct = GetProductFromTable()
        'Then your code goes here...
        DisplayTableOne(lstProduct)

    End Sub

    Public Function GetProductFromTable() As List(Of Product)
        Dim yourConfigConn As String = String.Empty
        ' yourConfigConn = You should supply your config connection here...
        Dim lstProd As New List(Of Product)
        Dim conn As SqlConnection = New SqlConnection(yourConfigConn)
        Dim sb As New StringBuilder

        Dim qry As String = sb.ToString()
        'qry = your query string here....
        ' This is just a CommandType query.... 
        Try
            Dim cmd As New SqlCommand(qry, conn)
            conn.Open()
            Using (cmd)
                cmd.CommandType = CommandType.Text
                Dim dr As SqlDataReader = cmd.ExecuteReader()
                Using (dr)
                    While (dr.Read())

                        Dim temp As New Product()
                        temp.Company = dr.Item("Company")
                        temp.Piece = dr.Item("Piece")
                        temp.Description = dr.Item("Description")
                        temp.Location = dr.Item("Location")
                        temp.Available = dr.Item("Available")
                        temp.Purchased = dr.Item("Purchased")
                        temp.ShipDate = dr.Item("ShipDate")
                        lstProd.Add(temp)
                    End While
                End Using

            End Using
        Catch ex As Exception
            Throw ex
        Finally
            conn.Close()
        End Try
        Return lstProd
    End Function

    Protected Sub displayTableOne(ByVal lstOfProducts As List(Of Product))
        ' Your code goes her...
        '.................

        Table1.DataSource = lstOfProducts
        Table1.DataBind()
    End Sub



End Class


Please vote if help...

Regards,

Algem
   
v3
Comments
Blue Jays Baseball Fan 17-Oct-11 13:44pm
   
I'm not sure what you mean for code in the lines:
lstProduct = GetProductFromTable()
'Then your code goes here...
DisplayTableOne(lstProduct)
Can you expand?
Al Moje 17-Oct-11 21:40pm
   
lstProduct is defind above as the public class of Product List Collection. GetProductFromTable() Is a public function that open the database table Product. Should be contains your query to your Database table. This function return the ListOf Product.
DisplayTableOne(lstProduct) May contains your additional code of validation that may inserted, then defined lstOfProducts as a DataSource in your defind Table1 grid, then bind.


If you are using local SQL Server your Web.Config may contains:
<connectionstrings>
<add name="yourConfigConn" connectionstring="Data Source=.;Initial Catalog=ClaimsSQL1;Integrated Security=True">

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