NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Imports MySql.Data.MySqlClient
Public Class Form1

Private db As New MySqlConnection
Private bruker As String
Private passord As String
Private server As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Text = "ericw"
TextBox3.Text = "mysql.stud.iie.ntnu.no"
End Sub

Private Function Sporring(ByVal sql As String) As DataTable

Dim tabell As New DataTable

Try

db.Open()

' Gjøre sql-spørring og fylle tabell med data

Dim kommando As New MySqlCommand(sql, db)

Dim da As New MySqlDataAdapter
da.SelectCommand = kommando
da.Fill(tabell)

db.Close()

Catch ex As MySqlException
MessageBox.Show("En feil oppstått - " & ex.Message)
End Try

Return tabell

End Function

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

db.ConnectionString = "Server=" & TextBox3.Text & ";" &
"Database=" & TextBox1.Text & ";" &
"Uid=" & TextBox1.Text & ";" &
"Pwd=" & TextBox2.Text & ";"

Try
db.Open()
MessageBox.Show(”Forbindelsen ble etablert med hell …”)
db.Close()
Catch myerror As MySqlException
MessageBox.Show(”Feil ved oppkobling mot databasen: ” & myerror.Message)
Finally
db.Dispose()
End Try

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Application.Exit()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
db.ConnectionString = "Server=" & TextBox3.Text & ";" &
"Database=" & TextBox1.Text & ";" &
"Uid=" & TextBox1.Text & ";" &
"Pwd=" & TextBox2.Text & ";"
Try
db.Open()
MsgBox("Alt gikk greit med å koble til databasen")
'Lager sentrale objekter
Dim sql As New MySqlCommand("SELECT * FROM personer", db)
Dim da As New MySqlDataAdapter
Dim interntabell As New DataTable
'Objektet "da" utfører spørringen og legger resultatet i "interntabell"
da.SelectCommand = sql
da.Fill(interntabell)
'Har ikke lenger bruk for å være tilkoblet til databasen
db.Close()
'En tabell har mange rader. DataRow-objektet kan lagre 1 rad om gangen
Dim rad As DataRow
Dim personid, fornavn, etternavn As String
'hjelpevariabler
'Fyller listeboksen med ønsket informasjon
ListBox1.Items.Clear()
'fjerner først eventuell gammel tekst
For Each rad In interntabell.Rows
personid = rad("id")
fornavn = rad("fornavn")
etternavn = rad("etternavn")
ListBox1.Items.Add(personid & " " & fornavn & " " & etternavn)
Next rad
Catch feilmelding As MySqlException
MsgBox("Feil ved tilkobling til databasen: " & feilmelding.Message)
Finally
db.Dispose()
End Try
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
db.ConnectionString = "Server=" & TextBox3.Text & ";" &
"Database=" & TextBox1.Text & ";" &
"Uid=" & TextBox1.Text & ";" &
"Pwd=" & TextBox2.Text & ";"
Try
db.Open()
MsgBox("Alt gikk greit med å koble til databasen")
'Lager sentrale objekter
Dim sql As New MySqlCommand("SELECT * FROM personer WHERE fornavn = '" & TextBox4.Text & "'", db)
Dim da As New MySqlDataAdapter
Dim interntabell As New DataTable
'Objektet "da" utfører spørringen og legger resultatet i "interntabell"
da.SelectCommand = sql
da.Fill(interntabell)
'Har ikke lenger bruk for å være tilkoblet til databasen
db.Close()
'En tabell har mange rader. DataRow-objektet kan lagre 1 rad om gangen
Dim rad As DataRow
Dim personid, fornavn, etternavn, epost, fodselsdato As String
'hjelpevariabler
'Fyller listeboksen med ønsket informasjon
ListBox2.Items.Clear()
'fjerner først eventuell gammel tekst
For Each rad In interntabell.Rows
personid = rad("id")
fornavn = rad("fornavn")
etternavn = rad("etternavn")
epost = rad("epost")
fodselsdato = rad("bursdag")
ListBox2.Items.Add(personid & " " & fornavn & " " & etternavn & " " & epost & " " & fodselsdato)
Next rad
Catch feilmelding As MySqlException
MsgBox("Feil ved tilkobling til databasen: " & feilmelding.Message)
Finally
db.Dispose()
End Try
End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
db.ConnectionString = "Server=" & TextBox3.Text & ";" &
"Database=" & TextBox1.Text & ";" &
"Uid=" & TextBox1.Text & ";" &
"Pwd=" & TextBox2.Text & ";"
Try
db.Open()
MsgBox("Alt gikk greit med å koble til databasen")
'Lager sentrale objekter
Dim sql As New MySqlCommand("SELECT * FROM personer WHERE epost like '%" & TextBox5.Text & "%'", db)
Dim da As New MySqlDataAdapter
Dim interntabell As New DataTable
'Objektet "da" utfører spørringen og legger resultatet i "interntabell"
da.SelectCommand = sql
da.Fill(interntabell)
'Har ikke lenger bruk for å være tilkoblet til databasen
db.Close()
'En tabell har mange rader. DataRow-objektet kan lagre 1 rad om gangen
Dim rad As DataRow
Dim personid, fornavn, etternavn, epost, fodselsdato As String
'hjelpevariabler
'Fyller listeboksen med ønsket informasjon
ListBox3.Items.Clear()
'fjerner først eventuell gammel tekst
For Each rad In interntabell.Rows
personid = rad("id")
fornavn = rad("fornavn")
etternavn = rad("etternavn")
epost = rad("epost")
fodselsdato = rad("bursdag")
ListBox3.Items.Add(personid & " " & fornavn & " " & etternavn & " " & epost & " " & fodselsdato)
Next rad
Catch feilmelding As MySqlException
MsgBox("Feil ved tilkobling til databasen: " & feilmelding.Message)
Finally
db.Dispose()
End Try
End Sub
End Class
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.