当我双击数据网格中的记录时。将显示另一个表单以编辑网格中的记录

时间:2016-01-20 07:30:18

标签: vb.net datagrid

我想知道如果我想在我的数据网格中双击现有数据该怎么办,我的编辑表格将显示,所有记录都在特定的文本框中。

我已经添加了删除模块

添加代码

If RequiredEntry() = True Then
        Return
    End If
    Try
        Dim cn As New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\BackUp\Database3.Accdb;")

        If cn.State = ConnectionState.Closed Then cn.Open()

        Dim sSQL As String = "insert into [userinfo]([username],[password],[FirstName],[LastName],[Account]) values(@username,@password,@FirstName,@LastName,@Account)"

        Dim cmd As OleDbCommand = New OleDbCommand(sSQL, cn)


        ' UserName
        If txtPassword.Text = txtConfirm.Text Then
            Dim username As OleDbParameter = New OleDbParameter("@username", OleDbType.VarWChar, 50)
            username.Value = txtUser.Text.ToString()
            cmd.Parameters.Add(username)
        Else
            MsgBox("Password not matched")

        End If

        'password
        Dim password As OleDbParameter = New OleDbParameter("@password", OleDbType.VarWChar, 50)
        password.Value = txtPassword.Text.ToString()
        cmd.Parameters.Add(password)


        'First Name
        Dim FirstName As OleDbParameter = New OleDbParameter("@FirstName", OleDbType.VarWChar, 50)
        FirstName.Value = txtFirstName.Text.ToString()
        cmd.Parameters.Add(FirstName)


        ' Last Name
        Dim LastName As OleDbParameter = New OleDbParameter("@LastName", OleDbType.VarWChar, 50)
        LastName.Value = txtLastName.Text.ToString()
        cmd.Parameters.Add(LastName)

        'Account

        Dim Account As OleDbParameter = New OleDbParameter("@Account", OleDbType.VarWChar, 50)
        Account.Value = cboAccount.GetItemText(cboAccount.SelectedItem)
        cmd.Parameters.Add(Account)



        If cmd.ExecuteNonQuery() Then
            cn.Close()
            MessageBox.Show("New User is Added successfully.", "Record Saved")
            Call clear()
            Me.Hide()
            FileMaintenance.Show()


        Else
            MsgBox("New User Addition Failed ", MsgBoxStyle.Critical, "Addition Failed")
            Return
        End If

    Catch ex As Exception
        Exit Sub
    End Try

这是我的删除代码

Dim connString As String = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\BackUp\Database3.Accdb;"
    Dim MyConn As OleDbConnection
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim tables As DataTableCollection
    Dim source1 As New BindingSource
    Dim rows As String


    Try
        MyConn = New OleDbConnection
        MyConn.ConnectionString = connString
        ds = New DataSet
        tables = (ds.Tables)
        rows = DataGridView1.SelectedRows(0).Cells(0).Value.ToString()
        da = New OleDbDataAdapter("Delete * from [userinfo] where ID=" & rows, MyConn)
        da.Fill(ds, "userinfo")
        Records_Load(sender, e)

    Catch ex As Exception
        MessageBox.Show("cannot delete empty records")
    End Try

0 个答案:

没有答案