表单的控件不会更新DataSet更改

问题描述 投票:0回答:1

我可以看到DataGridView变化很好但Form的控件没有更新。 据我所知,bs.ResetBindings(False)应该触发更新! 我已尝试从属性绑定选项卡绑定控件以及相同的结果!

但是我必须承认这是我在vb.net上的第一次尝试!

Imports System.Data.SqlClient

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        testdatTableAdapter.Fill(DATAHUBDataSet.testdat)
        bs = New BindingSource

        address.DataBindings.Add("text", bs, "address")
        typep.DataBindings.Add("text", bs, "type_projet")
        env.DataBindings.Add("text", bs, "enveloppe")
        ra.DataBindings.Add("text", bs, "region")
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'If Not IsNothing(ds.Tables("testdat")) Then
        '    ds.Tables.Clear()
        'End If

        da = Nothing
        ds = Nothing
        qry = "Select * from work.testdat where network = "
        qry &= "'" & resstrb.Text & "'"
        con.Close()
        con.Open()
        'qry = "Select * from work.testdat"
        cmd = New SqlCommand(qry, con)
        da = New SqlDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, "testdat")
        DataGridView1.DataSource = ds.Tables("testdat")
        bs.ResetBindings(False)
    End Sub
End class

Imports System.Data.SqlClient
'! note to mod, can't get this last bit of code to work with ctrl K 
Module test_sqldata
    Public str As String = getconstring()
    Public con As New SqlConnection(str)
    Public cmd As SqlCommand
    Public da As SqlDataAdapter
    Public ds As DataSet
    Public bs As BindingSource
    Public qry As String

    Public Function getconstring() As String
        Return "Data Source=XXXXXXX\YYYYYYYY;Initial Catalog=DATAHUB;Integrated Security=True"
    End Function
End Module
sql vb.net
1个回答
1
投票

将你的'bs'绑定到ds.datatable或删除'bs'并将你的文本框绑定到'ds.Tables(“testdat”)'如果看起来你可以清楚地看到网格和文本框正在使用2个不同的数据源,绑定源数据源根本没有设置,因此文本框绑定到空绑定源


推荐问答