如何从组合框中存储的linq过程加载数据?

时间:2009-01-12 13:46:31

标签: vb.net linq-to-sql stored-procedures combobox

我在dbml文件中存储过程,我想像这样做

 Private Sub GetData()
    Dim dal = New DataAccess
    Dim dateList = dal.context.GetAsDateList()
    Dim enumerator As IEnumerator = dateList.GetEnumerator()

    While enumerator.MoveNext()
      cmbDate.Items.Add(enumerator.Current)
    End While
  End Sub

但我有一个Null引用异常。这是怎么做到的?

GetAsDateList()过程是

BEGIN
 SET NOCOUNT ON
 SELECT DISTINCT YEAR(TRADE_DATE) AS [Year], MONTH(TRADE_DATE) AS [Month] FROM MyTable
 RETURN
END

1 个答案:

答案 0 :(得分:1)

你可以

吗?
Private Sub GetData()
    Dim dal = New DataAccess
    Dim dateList = dal.context.GetAsDateList()

    cmbData.DataSource = dateList
    cmbData.DataBind()
End Sub