使用Access数据库在vb.net中的INSERT INTO语句中的语法错误“如何解决?”

时间:2019-02-20 18:59:30

标签: vb.net

Private Sub Opretprofil_Click(sender As Object, e As EventArgs) Handles Opretprofil.Click
    Dim connection As New OleDbConnection(My.Settings.PakkeAppDatabaseConnectionString)
    If Email.Text = Nothing Or Passwordtillogin.Text = Nothing Or Gentagpassword.Text = Nothing Then
        MsgBox("Indtast din Email og dit Password", MsgBoxStyle.Critical)
    ElseIf Passwordtillogin.Text <> Gentagpassword.Text Then
        MsgBox("Udfyld venligt alle felter korrekt", MsgBoxStyle.Critical)
    Else

        Try
            If connection.State = ConnectionState.Closed Then
                connection.Open()
            End If
            Dim cmd As New OleDbCommand("insert into Table1(Email,Password) Value(?,?)", connection)
            cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = Email.Text
            cmd.Parameters.AddWithValue("@1", OleDbType.VarChar).Value = Passwordtillogin.Text

            cmd.ExecuteNonQuery()
            connection.Close()

            MsgBox("Profil er nu oprettet", MsgBoxStyle.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
End Sub

我认为问题出在这部分:

将cmd设置为新的OleDbCommand(“插入Table1(Email,Password)Value(?,?)”,连接)

1 个答案:

答案 0 :(得分:0)

最好标识参数,如果要使用AddWithValue,则必须提供值:

public static MyDatabase MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase obj) {
    return new MyDatabase(databaseJNI.MyDatabaseHandle_value(SWIGTYPE_p_MyDatabase.getCPtr(obj)), true);
}

希望获得帮助