如何从VB.Net中的数据集填充gridLookUp控件

时间:2014-07-10 20:20:14

标签: vb.net sql-server-2008 dataset

我使用VB.Net和SQL Server 2008.我想知道如何用我的DataSet中的数据填充GridLookUp控件。当我在SQL中传递查询时,它成功执行,这意味着它不是存储过程的问题。我错过了什么吗?看看我的例子。

txtStateGather.EditValue是我的GridLookUp控件的名称 - DevExpress控件

Private txtGatherLoaded As Boolean
Private gatherDs = New DataSet

Private Function GatherLoad()
    Try
        con.Close()
        con.Open()
        gatherDs = New Data.DataSet

        If txtGatherLoaded = False Then
            com = New SqlCommand("EXECUTE basicGatherSelect '" & txtStateID.Text & "','" & txtName.Text & "'", con)
            adp.SelectCommand = com
            adp.Fill(gatherDs)

            adp.dispose()
            com.Dispose()



            txtStateGather.Properties.DisplayMember = gatherDs.Tables(0).Columns(0).Caption.ToString
            txtStateGather.Properties.ValueMember = gatherDs.Tables(0).Columns(0).Caption.ToString
            txtStateGather.Properties.AutoComplete = True
            txtGatherLoaded = True

        End If

        If txtStateGather.EditValue Is Nothing Or txtStateGather.EditValue Is "" Or txtStateGather.EditValue Is System.DBNull.Value Or txtStateGather.Text = "" Then

            txtStateGather.EditValue = ""


        Else

            Dim rowHandle As System.Data.DataRowView
            rowHandle = txtStateGather.Properties.GetRowByKeyValue(txtStateGather.EditValue)
            txtStateGather.EditValue = rowHandle.Item(0).ToString
            txtStateGatherName.Text = rowHandle.Item(1).ToString
        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)

    Finally
        con.Close()



    End Try
End Function

1 个答案:

答案 0 :(得分:1)

看起来您在代码中的任何位置都没有设置DataSource:

txtStateGather.Properties.DisplayMember = gatherDs.Tables(0).Columns(0).Caption.ToString
txtStateGather.Properties.ValueMember = gatherDs.Tables(0).Columns(0).Caption.ToString
txtStateGather.Properties.DataSource = gatherDs.Tables(0)