datatable.AcceptChanges问题 Imports System.Data.
sqlClient Public Class Form1 Dim strcon As String = "uid=xxx;pwd=xxx;database=xxx;server=xxx " Dim mycon As New
sqlConnection(strcon) Dim mydc As New
sqlDataAdapter( "select * from 家庭开支 ",mycon) Dim dbset As New DataSet Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim mytab As New DataTable mytab = DataGridView1.DataSource Dim myrow As DataRow myrow = mytab.NewRow() myrow( "日期 ") = Now myrow( "金额 ") = Text
Box1.Text myrow( "使用人 ") = Combo
Box1.Text myrow( "说明 ") = Text
Box2.Text mytab.Rows.Add(myrow) mytab.AcceptChanges() End Sub Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load ''TODO: 这行
代码将数据加载到表“SosyDataSet.家庭开支”中。您可以根据需要移动或移除它。 '' Me.家庭开支TableAdapter.Fill(Me.SosyDataSet.家庭开支) mycon.Open() mydc.Fill(dbset,"家庭开支 ") DataGridView1.DataSource = dbset.Tables( "家庭开支 ") End Sub End Class ''运行提交数据,在程序里发生了更改,在
数据库里查看没有任何变. __________________________________________________________________________ mytab.AcceptChanges() -------------------------------- 只是清除各个行的更改状态, 要更改必须用数据适配器的update()
方法 __________________________________________________________________________ mydc.Update(mytab.GetChanges)是这句话??? mytab.AcceptChanges() 我现在用的是vs.net2005,以前用vs.net2003行得通 __________________________________________________________________________ 来学习滴,研究研究,偶是VS菜鸟 __________________________________________________________________________ 不太明白. 你是要往
数据库里插入记录?还是要更新记录? __________________________________________________________________________ 不太明白. 你是要往
数据库里插入记录?还是要更新记录? __________________________________________________________________________ mytab.AcceptChanges() 位置
错误 Dim mytab As New DataTable mytab = DataGridView1.DataSource mytab.AcceptChanges() Dim myrow As DataRow myrow = mytab.NewRow() myrow( "日期 ") = Now myrow( "金额 ") = Text
Box1.Text myrow( "使用人 ") = Combo
Box1.Text myrow( "说明 ") = Text
Box2.Text mytab.Rows.Add(myrow) __________________________________________________________________________ 上面的
代码确实有问题: 1.不知道楼主是要更新
数据库吗?,如果要更新应该是这样的. VB.NET code Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click Dim mytab As New DataTable mytab = DataGridView1.DataSource Dim myrow As DataRow myrow = mytab.NewRow() myrow( "日期 ") = Now myrow( "金额 ") = Text
Box1.Text myrow( "使用人 ") = Combo
Box1.Text myrow( "说明 ") = Text
Box2.Text mytab.Rows.Add(myrow) mydc.Update(mytab) -- 不是 mytab.AcceptChanges() End Sub 执行 mydc.Update(mytab) 后,你就不需要再 mytab.AcceptChanges(),系统已经在Update
后执行过一次. __________________________________________________________________________