Brugernavn:




Kodeord: Husk
Forside Forum Artikler Downloads Søg
 

Connecte til database via VB

Hejsa, Rowlere. Hvordan kan man via Visual Basic lave et login, hvori den hente fra tabellen brugere og felterne id,kode,brugernavn, :D?
(skal lave et login lissom steam man =])

- Perfektion
Oprettet af:

Visual Basic

Fri debat

Åben
16:48 22/07/2010
du bør nok nævne hvilken database du bruger
Oprettet af:

Kommentar
17:00 22/07/2010
Danni jeg har os lavet en tråd om dette.
http://rowl.dk/Forum/31036 og jeg skal os have connecte til en database fra phpmyadmin.
man kan os med en database man selv laver i Office access.
http://www.youtube.com/watch?v=NlH167_voXU eller
http://www.youtube.com/watch?v=p0dcPiLYrck eller
http://www.youtube.com/watch?v=PcRqwmtyMeU&feature=related kan ikke finde mere på youtube
Sidst redigeret 17:58 22/07/2010 af Rowl
Oprettet af:

Kommentar
17:40 22/07/2010
Brug nu Google for filan!

Søgte på "vb mysql connection"

Det allerførste resultat er brugbart ;)
Oprettet af:

Kommentar
17:53 22/07/2010
  1. Dim strDataBaseName As String
  2. Dim strDBCursorType As String
  3. Dim strDBLockType As String
  4. Dim strDBOptions As String
  5. Dim rs As ADODB.Recordset
  6. Dim cn As ADODB.Connection

  7. Private Sub Command1_Click()
  8. On Error GoTo Command1_Click_Error
  9. Dim b as Long
  10. strDBCursorType = adOpenDynamic  'CursorType
  11. strDBLockType = adLockOptimistic   'LockType
  12. strDBOptions = adCmdText         'Options

  13. Set cn = New ADODB.Connection
  14. Me.MousePointer = 11

  15. cn.Open ConnectString()
  16.     
  17.     With cn
  18.         .CommandTimeout = 0
  19.         .CursorLocation = adUseClient
  20.     End With

  21.     Set rs = New ADODB.Recordset       'Creates record set

  22.     strSQL = "<Your SQL Here>"
  23.     
  24.     rs.Open strSQL, cn, strDBCursorType, strDBLockType, strDBOptions
  25.     

  26. if rs.Eof then
  27.    Goto ExitSub    
  28. else
  29.     For b = 1 To rs.RecordCount
  30.     '<do whatever you need to do with the data here>
  31.     Next b
  32. end if
  33.     
  34. ExitSub:

  35. rs.Close
  36. Set rs = Nothing
  37. cn.Close
  38. Set cn = Nothing

  39. On Error GoTo 0
  40. Exit Sub

  41. Command1_Click_Error:
  42.     MsgBox "Error " & Err.Number & " (" & Err.Description & ")  & _
  43.                      in procedure Command1_Click of Form " & Me.Name
  44. End Sub

  45. Private Function ConnectString() As String
  46. Dim strServerName as String
  47. Dim strDatabaseName as string
  48. Dim strUserName as string
  49. Dim strPassword as string

  50.     'Change to IP Address if not on local machine
  51.     'Make sure that you give permission to log into the
  52.     'server from this address
  53.     'See Adding New User Accounts to MySQL
  54.     'Make sure that you d/l and install the MySQL Connector/ODBC 3.51 Driver

  55. strServerName = "localhost"
  56. strDatabaseName = "DatabaseName"
  57. strUserName = "UserName"
  58. strPassword ="Password"

  59. ConnectString = "DRIVER={MySQL ODBC 3.51 Driver};" & _
  60.                 "SERVER=" & strServerName & _
  61.                 ";DATABASE=" & strDatabaseName & ";" & _
  62.                 "USER=" & strUserName & _
  63.                 ";PASSWORD=" & strPassword  & _
  64.                 ";OPTION=3;"

  65. End Function
Oprettet af:

Kommentar
18:10 22/07/2010
Du skal være oprettet og logget ind for at svare på en tråd
Copyright © Rowl.dk v/ Michael Raagaard | 2005-12 | Alle rettigheder forbeholdes