VB SQL数据库INSERT未保存

时间:2012-05-05 02:56:06

标签: sql database vb.net insert

所以我在visual basic项目中添加了一个基于服务的数据库。此时项目仅存在登录或注册,之后您将登录。

现在我的所有SQL似乎都正确且有效,代码很好,但是当我注册新用户时,它不会存储在数据库中。但它确实存储了......

我知道听起来很奇怪,我的意思是显然数据存储在某处,因为我检查用户名是否已经存在。如果它,我得到一个消息框。现在奇怪的是,在构建和运行之间,它会记住我注册的所有用户,但是当我关闭程序并稍后重新打开它时,所有数据都消失了......

我使用参数插入日期,所有内容都来自以下代码:


    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
            Dim strUser, strPass As String
            Dim sql As New usersDataSetTableAdapters.usersTableAdapter
            Dim con As New SqlClient.SqlConnection
            Dim com As New SqlClient.SqlCommand
            Dim adaptor As New SqlClient.SqlDataAdapter
            Dim dataset As New DataSet
            strUser = txtUser.Text
            strPass = txtPass.Text
            If lblRegister.Text = "Login" Then
                Dim strPassConfirm As String
                strPassConfirm = txtPassConfirm.Text
                If strPass = strPassConfirm Then
                    If sql.usernameCheck(strUser) = 1 Then
                        MessageBox.Show("Username already in use", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    Else
                        sql.addUser(strUser, strPass)
                    End If

                Else
                    MessageBox.Show("Passwords do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                End If
            Else
                Dim c As Integer = sql.CheckUser(strUser, strPass)
                If c = 1 Then
                    'form2.show()
                    MessageBox.Show("succes")
                End If
            End If
        End Sub

这是使用的SQL:


    INSERT INTO [dbo].[users] ([username], [password]) VALUES (@username, @password)

和图片,也许它有助于理解......

enter image description here

1 个答案:

答案 0 :(得分:0)

您好我想检查整个代码......,但是看起来缺失的东西是在数据集中调用 .AcceptChanges()方法,以便在数据库中提交更改。< / p>

相关问题