如何在vb.net中将数据插入到访问数据库中

时间:2016-10-10 11:07:59

标签: asp.net vb.net

这是代码。问题是每次运行代码时都会覆盖表值。请给出一些解决方案

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox2.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
    MsgBox("Please fill the details")
Else
    Try

        Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\bin\hr.accdb;")
            conn.Open()

            Dim command As New OleDbCommand("insert into admin (uname,pwd) values (@uname, @pwd)", conn)

            With command.Parameters
                .AddWithValue("@uname", TextBox1.Text)
                .AddWithValue("@pwd", TextBox2.Text)

            End With

            command.ExecuteNonQuery()

            MessageBox.Show("Employee's Informations Successfuly Recorded!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)

            command.Dispose()
            conn.Close()

            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox3.Text = ""
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End If

0 个答案:

没有答案