[VB.NET]datatable.AcceptChanges问题

前端之家收集整理的这篇文章主要介绍了[VB.NET]datatable.AcceptChanges问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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( "金额 ") = TextBox1.Text myrow( "使用人 ") = ComboBox1.Text myrow( "说明 ") = TextBox2.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( "金额 ") = TextBox1.Text myrow( "使用人 ") = ComboBox1.Text myrow( "说明 ") = TextBox2.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( "金额 ") = TextBox1.Text myrow( "使用人 ") = ComboBox1.Text myrow( "说明 ") = TextBox2.Text mytab.Rows.Add(myrow) mydc.Update(mytab) -- 不是 mytab.AcceptChanges() End Sub 执行 mydc.Update(mytab) 后,你就不需要再 mytab.AcceptChanges(),系统已经在Update后执行过一次. __________________________________________________________________________ 原文链接:https://www.f2er.com/vb/263827.html

猜你在找的VB相关文章