数据没有在DataGrid中更新..? (错误)我不知道源代码有什么问题 [英] the data is not updated in the DataGrid ..? (error) I do not know what's wrong with sourcecode

查看:65
本文介绍了数据没有在DataGrid中更新..? (错误)我不知道源代码有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.Data.OleDb



Public Class Form1

Dim con As New OleDbConnection



私有属性TableAdapter As Object



Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load

'TODO:这行代码将数据加载到'Database21DataSet.Table1'表中。您可以根据需要移动或移除它。

Me.Table1TableAdapter.Fill(Me.Database21DataSet.Table1)

尝试

con。 ConnectionString =provider = microsoft.jet.oledb.4.0; data source = .. \ Database.mdb

con.Open()

showMyRecords()

con.Close()



Catch ex As Exception



结束尝试< br $>
End Sub

Public Sub showMyRecords()

Dim dt As New DataTable

Dim ds As New DataSet

ds.Tables.Add(dt)

Dim da As New OleDbDataAdapter(select * from Table1,con)

da.Fill(dt )



Dim myRow As DataRow

每个myRow in dt.Rows





ListView1.Items.Add(myRow.Item(0))

ListView1.Items(ListView1.Items.Count - 1).SubIte ms.Add(myRow.Item(1))

ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(2))

ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(3))

ListView1.Items(ListView1.Items.Count - 1).SubItems.Add( myRow.Item(4))





下一页

结束子



Private Sub Button6_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button6.Click

Table1BindingSource.AddNew()



结束子



私有子按钮7_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button7.Click < br $>
TableAdapter.Update(Database21DataSet.Table1)



结束子



私人Sub Button8_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button8.Click

Table1 BindingSource.RemoveCurrent()



结束子

结束类

Imports System.Data.OleDb

Public Class Form1
Dim con As New OleDbConnection

Private Property TableAdapter As Object

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database21DataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Database21DataSet.Table1)
Try
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=..\Database21.mdb"
con.Open()
showMyRecords()
con.Close()

Catch ex As Exception

End Try
End Sub
Public Sub showMyRecords()
Dim dt As New DataTable
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim da As New OleDbDataAdapter("select * from Table1", con)
da.Fill(dt)

Dim myRow As DataRow
For Each myRow In dt.Rows


ListView1.Items.Add(myRow.Item(0))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(1))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(2))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(3))
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myRow.Item(4))


Next
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Table1BindingSource.AddNew()

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TableAdapter.Update(Database21DataSet.Table1)

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Table1BindingSource.RemoveCurrent()

End Sub
End Class

推荐答案

我认为你缺少BindingSource.EndEdit();



我的C#代码我有一个GridView但应该也一样。



为了更新,我有:

I think you're missing BindingSource.EndEdit();

in my C# code I had a GridView but should work the same.

For update, I had:
private void LoadLookupTable()
        {
            this.eventLookupTableAdapter.Fill(this.configDBDataSet.EventLookup);
            this.eventLookupBindingSource.DataSource = this.configDBDataSet.EventLookup;
        }

private void UpdateTable()
{
this.eventLookupBindingSource.EndEdit();
int n = this.eventLookupTableAdapter.Update(this.configDBDataSet.EventLookup);
this.LoadLookupTable();
}





对于添加和删除,我访问了DataSet.DataTable.Rows。



For add and delete I accessed DataSet.DataTable.Rows.


这篇关于数据没有在DataGrid中更新..? (错误)我不知道源代码有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆