The program can run , but after i insert the user detail and go to refresh the dataTable
i get this error msg
"This database cannot be imported "

Imports System.Data
Imports System.Data.SqlClient
Public Class frmMain
    Dim con As SqlConnection
    Dim cmd As SqlCommand
    Dim adapter As SqlDataAdapter
    Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        con = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|users.mdf;Integrated Security=True")


    End Sub

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Dim query As String = "SELECT fullname FROM users WHERE username = @username AND password = @password"
        cmd = New SqlCommand(query, con)
        cmd.Parameters.AddWithValue("username", txtUsernameLogin.Text)
        cmd.Parameters.AddWithValue("password", txtPasswordLogin.Text)

        adapter = New SqlDataAdapter(cmd)
        Dim dtSet As DataSet = New DataSet()
        adapter.Fill(dtSet, "MatchedUser")
        Dim dtTable As DataTable = dtSet.Tables("MatchedUser")
        If (dtTable.Rows.Count > 0) Then
            Dim dr As DataRow = dtTable(0)
            Dim fullname As String = dr("fullname")
            MsgBox("Welcome back, " & fullname & "!")
            MsgBox("Username/password mismatch.")
        End If
    End Sub

    Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
        Dim queryInsert As String = "INSERT INTO users(username,password,fullname,ic,phoneNo,email)" & " VALUES(@un,@pwd,@fnm,@ic,@pn,@em)"
        cmd = New SqlCommand(queryInsert, con)

        cmd.Parameters.AddWithValue("@un", txtUsernameReg.Text)
        cmd.Parameters.AddWithValue("@pwd", txtPasswordReg.Text)
        cmd.Parameters.AddWithValue("@fnm", txtFullnameReg.Text)
        cmd.Parameters.AddWithValue("@ic", txtICReg.Text)
        cmd.Parameters.AddWithValue("@pn", txtPhoneNoReg.Text)
        cmd.Parameters.AddWithValue("@em", txtEmailReg.Text)

        MsgBox("Records Saved Successfully")

    End Sub
End Class
Member Avatar

"This database cannot be imported "

It sound like a connection problem.

There should be a error log to let you know why in detail.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.