Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

Połączenie z Bazą mysql


Rekomendowane odpowiedzi

Opublikowano

Tak jak wyżej

 

W Public Class mam coś takiego

Public Class Form1
    'Represents an SQL statement or stored procedure to execute against a data source.
    Dim cmd As New MySqlCommand
    Dim da As New MySqlDataAdapter
    'declare conn as connection and it will now a new connection because 
    'it is equal to Getconnection Function
    Dim con As  = jokenconn()

    Public Function jokenconn() As MySqlConnection
        Return New MySqlConnection("server=localhost;user id=root;password=;database=studentdb")
    End Function

Pod buttonem login mam cos takiego

Dim sql As String
        Dim publictable As New DataTable
        Try
            'check if the textbox is equal to nothing then it will display the message below!.
            If txtuname.Text = "" And txtpass.Text = "" Then
                MsgBox("Password or Username Incorrect!")
 
            Else
                sql = "select * from tbluseraccounts where username ='" & txtuname.Text & "' and userpassword = '" & txtpass.Text & "'"
                'bind the connection and query
                With cmd
                    .Connection = con
                    .CommandText = sql
                End With
                da.SelectCommand = cmd
                da.Fill(publictable)
                'check if theres a result by getting the count number of rows
                If publictable.Rows.Count > 0 Then
 
                    'it gets the data from specific column and assign to the variable
                    Dim user_type, name As String
                    user_type = publictable.Rows(0).Item(4)
                    name = publictable.Rows(0).Item(2)
                    'check if the type of user is admin
                    If user_type = "Admin" Then
                        'welcomes the user as Admiistrator
                        MsgBox("Welcome " & name & " you login as Administrator ")
                        'set the lbllogin text to Logout 
                        lbllogin.Text = "Logout"
                        'disabled the groupbox
                        GroupBox1.Enabled = False
                        'reset all the two textbox
                        txtuname.Text = ""
                        txtpass.Text = ""
                        'set the lblname to the specific user
                        lblname.Text = "Hi, " & name
 
                    ElseIf user_type = "Encoder" Then
                        MsgBox("Welcome " & name & " you login as Encoder ")
                        lbllogin.Text = "Logout"
                        GroupBox1.Enabled = False
                        txtuname.Text = ""
                        txtpass.Text = ""
                        lblname.Text = "Hi, " & name
                    Else
                        MsgBox("You login as Guest!")
                        lbllogin.Text = "Logout"
                        GroupBox1.Enabled = False
                        txtuname.Text = ""
                        txtpass.Text = ""
                        lblname.Text = "Hi, " & name
                    End If
 
                Else
                    MsgBox("Contact administrator to registered!")
                    txtuname.Text = ""
                    txtpass.Text = ""
                End If
 
                da.Dispose()
            End If
 
        Catch ex As Exception
            MsgBox(ex.Message)
 
        End Try
        con.Clone()

Wszystko niby super tylko że

jzblko.jpg

logo.png


Spudgy™


L# to gówno


Bol 3.0


S

Opublikowano

Przypadkiem nie masz zaimportowanej biblioteki MySQL?

mam tylko to:

Imports System.Net
Imports System.IO
Imports System.Text

logo.png


Spudgy™


L# to gówno


Bol 3.0


S

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...