Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I'm trying to bind the data to a drop down list, here is the code:

VB
Private Sub BindVendors()
        With New GlobalSystems
            dsGlobal = New GlobalData
            storeID = CInt(Session("STOREID"))
            If storeID <> 0 Then
                dsGlobal = .GetVendorLotto(storeID)
                If Not dsGlobal Is Nothing Then
                    Session.Add("dsVendorsList", dsGlobal)
                    ddlVendor.DataSource = dsGlobal.Tables(Vendor_Data.TBL_VENDORPROFILE)
                    ddlVendor.DataTextField = Vendor_Data.COMPANYNAME
                    ddlVendor.DataValueField = Vendor_Data.VENDORID
                    ddlVendor.DataBind()
                    ddlVendor.Items.Insert(0, New ListItem("-Select Any-", "-1"))
                End If
         End If
     End With
End Sub


Function to get the vendor details

VB
Public Function GetVendorLotto(ByVal StoreID As Int32) As GlobalData
            'This function is for getting all vendors who supply Lottery Games to a store
            With New GlobalAccess
                GetVendorLotto = .GetVendorLotto(StoreID)
            End With
        End Function


In the below code the result is showing 0. But the data is there in the table.

SQL
Public Function GetVendorLotto(ByVal storeID As Int32) As GlobalData
            dsGlobal = New GlobalData
            With sqlaAccounts
                .SelectCommand = GetSelectCommand("usp_GetVendorAgainstStoreNLottery", 3)
                .SelectCommand.Parameters("@storeID").Value = storeID
                result = .Fill(dsGlobal, Vendor_Data.TBL_VENDORPROFILE
            End With
            If result > 0 Then
                If dsGlobal Is Nothing Then
                Else
                    GetVendorLotto = dsGlobal
                End If
            End If
        End Function



VB
Private Function GetSelectCommand(ByVal storedProcName As String, ByVal whichCommand As Int16) As SqlCommand
            sqldCommand = New SqlCommand(storedProcName, New SqlConnection(CStoresConfiguration.ConnectionString))
            sqldCommand.CommandType = CommandType.StoredProcedure
       If whichCommand = 3 Then
               With sqldCommand.Parameters
                   .Add(New SqlParameter("@storeID", SqlDbType.Int))
               End With
           End If
       GetSelectCommand = sqldCommand
  End Function


There is data in the database, but the data is not binding.

Can someone help me please?
Posted
Updated 1-Jun-11 22:07pm
v5

1 solution

Just a couple of comments on the coding style... Don't use With...End With extensively. It makes the code hard to read.

Also, use the Return statement instead of assigning the return value to the name of the function. That's the old VB6/VBScript style of returning values.

Your short GetVendorLotto function can be rewritten into a single line of code that's more understandable.

You're using "global" DataAdapters. Don't. Write a method that builds a DataAdapter on demand when needed.

You're also using "magic numbers" in your code. The second parameter passed to GetSelectCommand should be an enum, not an arbitrary Int16 value. Again, it makes the code more readable.


As for the problem, it appears everything is being setup, but it's difficult to follow the code because it's jumping all over the place trying to assemble an SQL query.

Write a test method that's a very simplified version of all of this and see if the stored proc is actually returning anything. After that, step through to code line-by-line in the debugger and follow what the variables are doing.
 
Share this answer
 
Comments
randheer kumar 10-Jun-11 8:25am    
thank you for taking out the time for analyzing the code.i will try to do as you explained.

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