1插入或保存2个或更多数据库的按钮

时间:2015-07-06 02:00:57

标签: database vb.net

我正在创建一个数据库管理系统。我这里有四个(和计数)数据库,但我想知道是否可以只为2个或更多数据库使用1个插入或保存按钮?

我是vb.net的新人。

下面是我的插入或保存按钮的代码。而且我无法继续下去,因为我在想是否有可能只为许多数据库使用1个插入或保存按钮。

Private Sub btnSaveOPR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveOPR.Click
        provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
        'Change the following to your access database location
        dataFile = "C:\Users\DELL\Downloads\ODRNEWSYSTEM\ODRNEWSYSTEM\Database1.accdb"
        connString = provider & dataFile
        myConnection.ConnectionString = connString
        myConnection.Open()
        Dim str As String
        str = "insert into OPR ([OPROffice], [ID], [Elements], [Objectives], [Measures],[Baseline_as_of_2013],[Target_by_2016],[Actual_Accomplishments_2014],[Actual_Accomplishments_2015],[Actual_Accomplishments_2016],[Initiatives]) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
        cmd.Parameters.Add(New OleDbParameter("OPROffice", CType(OPROfficeTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("ID", CType(IDTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Elements", CType(ElementsTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Objectives", CType(ObjectivesTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Measures", CType(MeasuresTextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Baseline_as_of_2013", CType(Baseline_as_of_2013TextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Target_by_2016", CType(Target_by_2016TextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_Accomplishments_2014", CType(Actual_Accomplishments_2014TextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_Accomplishments_2015", CType(Actual_Accomplishments_2015TextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Actual_Accomplishments_2016", CType(Actual_Accomplishments_2016TextBox.Text, String)))
        cmd.Parameters.Add(New OleDbParameter("Initiatives", CType(InitiativesTextBox.Text, String)))
        Try
            cmd.ExecuteNonQuery()
            cmd.Dispose()
            myConnection.Close()
            Me.Validate()
            Me.OPRBindingSource.EndEdit()
            Me.OPRTableAdapter.Update(Me.Database1DataSet.OPR)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        RefreshData()
        OPRDataGridView.RefreshEdit()
    End Sub

0 个答案:

没有答案