数据没有绑定,但是没有错误? [英] Data is not binding, but no error?
本文介绍了数据没有绑定,但是没有错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数据绑定到下拉列表,这是代码:
Hi,
I''m trying to bind the data to a drop down list, here is the code:
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
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
在下面的代码中,结果显示为0.但是表中有数据.
In the below code the result is showing 0. But the data is there in the table.
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
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?
推荐答案
仅对编码风格发表几点评论...请勿与...一起广泛使用.它使代码难以阅读.
另外,请使用Return语句,而不是将返回值分配给函数名称.那是返回值的旧VB6/VBScript样式.
您短的GetVendorLotto
函数可以重写为更容易理解的单行代码.
您正在使用全局" DataAdapter.别.编写一种在需要时按需构建DataAdapter的方法.
您还在代码中使用魔术数字".传递给GetSelectCommand
的第二个参数应该是一个枚举,而不是一个任意的Int16值.同样,它使代码更具可读性.
至于问题,似乎所有东西都在设置中,但是很难遵循代码,因为它在试图组装SQL查询的过程中四处跳跃.
编写一个测试方法,将其简化为所有版本,然后查看存储的proc是否实际上返回了任何东西.之后,逐步在调试器中逐行进行编码,并跟踪变量的作用.
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 shortGetVendorLotto
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 toGetSelectCommand
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.
这篇关于数据没有绑定,但是没有错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文