datagridview 的使用问题
form1的代码为:
Public Class Form1
Private Sub StudyBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.StudyBindingSource.EndEdit()
Me.StudyTableAdapter.Update(Me.StudyDataSet.study)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: 这行代码将数据加载到表“StudyDataSet.study”中。您可以根据需要移动或移除它。
Me.StudyTableAdapter.Fill(Me.StudyDataSet.study)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Form2.show()
End Sub
End Class
form1中的datagridview是直接拖动数据源上的表到窗体上实现的。
form2的代码为:
Imports System.Data.OleDb
Public Class form2
Private connStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\datagridview\datagridview\study.mdb"
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
Dim SQLString As String = "INSERT INTO study VALUES('" + txtID.Text + "','" + txtName.Text + "', '" + txtSex.Text _
+ "', '" + txtAddress.Text + "' )"
'调用编辑数据的模块
Dim count As Integer = EditData.Insert(connStr, SQLString)
If count > 0 Then
MsgBox("添加数据成功!", MsgBoxStyle.OkOnly, "添加数据内容")
End If
End Sub
End Class
怎样才能实现当在form2中新增数据点击“确定”按钮后,form1中的datagridview中实现动态更新。
补充:VB , 控件