在VB中将数据插入表但在表中没有显示

时间:2015-09-09 09:48:27

标签: sql vb.net

这是我的代码。没有显示错误。我插入到数据表中,但数据未显示在表中。任何人都可以解决这个问题吗?。

Public Class Form11

    Private Sub btnCreate_Click(sender As Object, e As EventArgs) Handles btnCreate.Click

        Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=loginUser.mdb;")
        Dim command As New OleDbCommand("SELECT COUNT(*) FROM [Staff]", connection)

        command.Connection.Open()
        Dim count As Int16 = Convert.ToInt16(command.ExecuteScalar())
        command.Connection.Close()
        count = count + 1
        MsgBox(count)

        Dim command1 As New OleDbCommand("INSERT INTO Staff ([ID], [username], [password]) VALUES (@id,@user,@pass)", connection)

        With command1.Parameters
            .AddWithValue("@id", count)
            .AddWithValue("@user", txtUsername.Text)
            .AddWithValue("@pass", txtPassword.Text)
        End With
        Using connection
            command1.Connection.Open()
            command1.ExecuteNonQuery()
        End Using
        command1.Connection.Close()
        MsgBox("Added")
    End Sub

End Class

0 个答案:

没有答案