从模块填充数据网格

时间:2014-09-26 10:01:40

标签: vb.net datagridview

我正在尝试从单独模块中的sub填充数据网格。我必须遗漏一些非常简单的东西,但我似乎无法找到错误的东西。我的网格中没有数据显示。

Public Sub FilldgvChargesPerContract(ByVal TelNr As String)
    'opvullen van de overzichtsgrid Charges Per Contract
    Dim strSQL As String = ""
    Dim oDR As SqlClient.SqlDataReader = Nothing

    strSQL = " SELECT INVOICEPERIOD AS PERIOD, CATEGORY, SERVICE,AMOUNT FROM MOBILECOSTS_MOBISTAR_CHARGESPERCONTRACT WHERE PHONENR = '" & TelNr & "' AND DATEFROM > '1900-01-01' ORDER BY SERVICE DESC "

    Dim connection As New SqlConnection(SQLConnectstring)
    Dim dataadapter As New SqlDataAdapter(strSQL, connection)
    Dim ds As New DataSet()
    connection.Open()
    dataadapter.Fill(ds, "MOBILECOSTS_MOBISTAR_CHARGESPERCONTRACT")
    connection.Close()
    frmMobileCosts.dgvChargesPerContract.DataSource = ds
    frmMobileCosts.dgvChargesPerContract.DataMember = "MOBILECOSTS_MOBISTAR_CHARGESPERCONTRACT"
    frmMobileCosts.dgvChargesPerContract.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    'dgvOverviewNew.TopLeftHeaderCell.Value = "reset"
    frmMobileCosts.dgvChargesPerContract.TopLeftHeaderCell.Style.ForeColor = System.Drawing.Color.Blue

    'Laatste kolom uitbreiden voor het opvullen van de hele grid en alle andere cellen net groot genoeg voor inhoud
    frmMobileCosts.dgvChargesPerContract.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    frmMobileCosts.dgvChargesPerContract.Columns("AMOUNT").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

End Sub

1 个答案:

答案 0 :(得分:0)

看起来你错过了以下一行......

frmMobileCosts.dgvChargesPerContract.DataBind()

如果不这样做,您可能希望让模块中的方法返回生成的DataSet,然后在frmMobileCosts上的函数调用中将其数据绑定到DataGridView。