0

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")

        con.Open()


    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 & "!")
        Else
            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)


        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Records Saved Successfully")

    End Sub
End Class

Edited by on93: typing error

2
Contributors
1
Reply
7
Views
4 Years
Discussion Span
Last Post by LastMitch
0

"This database cannot be imported "

It sound like a connection problem.

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.