교컴로고초기화면으로 header_kyocom
교컴메뉴
교컴소개 이용안내 소셜교컴 나눔마당 배움마당 자료마당 교과마당 초등마당 특수마당 글로벌교컴 온라인프로젝트학습 교컴 UCC
회원 로그인
정보기억 정보기억에 체크할 경우 다음접속시 아이디와 패스워드를 입력하지 않으셔도 됩니다.
그러나, 개인PC가 아닐 경우 타인이 로그인할 수 있습니다.
PC를 여러사람이 사용하는 공공장소에서는 체크하지 마세요.
소셜네트워크 서비스를 통해서 로그인하시면 별도의 로그인 절차없이 회원서비스를 이용하실 수 있습니다.
교컴 키우기 자발적 후원


:::: 교컴가족 로그인(0)

  • 주간 검색어
  • 현재 검색어
  1. 갑사로 가는 길
  2. 시험감독
  3. bettyheeya
  4. 자유학기
  5. 대입 진학 상담 일지 양식
  6. 예시문
  7. 체육 특기사항
  8. 교무
기간 : 현재기준

교컴 포토갤러리

컴퓨터

ASP나 VB에서 ADO,DAO,RDO를 위한 MySQL연결하기

8175 | 2004.01.25 19:26 | 조회 17472 | 공감 0 | 비공감 0
ASP나 VB에서 ADO,DAO,RDO를 위한 MySQL연결하기

홈피를 만들거나 프밍을 하는 사람이아면 기본적으로 알아야 할 내용이지요.
워낙 많이 쓰는 거라 필요할 때 찾기 귀찮죠.
MS SQL이나 Oracle DB나 사용법에는 차이가 없습니다. 단지 드라이버 선택이 다를 뿐입니다
VB 6 나 ASP 로 MySQL Database를 연결해서 사용할 때는 먼저 MyODBC 3.51.06 다운 받아야 한다. 주소는 http://www.mysql.com/downloads/api-myodbc-3.51.html

'**************************************
' ADO 사용하기
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim fld As ADODB.Field
Dim sql As String
'connect to MySQL server using MySQL ODBC 3.51 Driver
Set conn = New ADODB.Connection
conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=test; UID=venu; PWD=venu; OPTION=3"
conn.Open
'table 생성하기
conn.Execute "DROP TABLE if EXISTS my_ado"
conn.Execute "CREATE TABLE my_ado(id int Not null primary key, name varchar(20)," _
& "txt text, dt date, tm time, ts timestamp)"
'direct insert
conn.Execute "INSERT INTO my_ado(id,name,txt) values(1,100,'venu')"
conn.Execute "INSERT INTO my_ado(id,name,txt) values(2,200,'MySQL')"
conn.Execute "INSERT INTO my_ado(id,name,txt) values(3,300,'Delete')"
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseServer
'fetch the initial table ..
rs.Open "SELECT * FROM my_ado", conn
Debug.Print rs.RecordCount
rs.MoveFirst
Debug.Print String(50, "-") & "Initial my_ado Result Set " & String(50, "-")
For Each fld In rs.Fields
Debug.Print fld.Name,
Next
Debug.Print
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld.Value,
Next
rs.MoveNext
Debug.Print
Loop
rs.Close
'rs insert(레코드삽입)
rs.Open "select * from my_ado", conn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!Name = "Monty"
rs!txt = "Insert row"
rs.Update
rs.Close
'rs update(레코드 업데이트)
rs.Open "SELECT * FROM my_ado"
rs!Name = "update"
rs!txt = "updated-row"
rs.Update
rs.Close
'rs update second time..
rs.Open "SELECT * FROM my_ado"
rs!Name = "update"
rs!txt = "updated-second-time"
rs.Update
rs.Close
'rs delete
rs.Open "SELECT * FROM my_ado"
rs.MoveNext
rs.MoveNext
rs.Delete
rs.Close
'업데이트 체이블 검사하기
rs.Open "SELECT * FROM my_ado", conn
Debug.Print rs.RecordCount
rs.MoveFirst
Debug.Print String(50, "-") & "Updated my_ado Result Set " & String(50, "-")
For Each fld In rs.Fields
Debug.Print fld.Name,
Next
Debug.Print
Do Until rs.EOF
For Each fld In rs.Fields
Debug.Print fld.Value,
Next
rs.MoveNext
Debug.Print
Loop
rs.Close
conn.Close

'*******************************************************
' DAO 사용하기
Dim ws As Workspace
Dim conn As Connection
Dim queryDef As queryDef
Dim str As String
'MySQL ODBC 3.51를 사용하여 MySQL에 연결하기
' Driver
Set ws = DBEngine.CreateWorkspace("", "venu", "venu", dbUseODBC)
str = "odbc;DRIVER={MySQL ODBC 3.51 Driver};"_
& "SERVER=localhost;"_
& " DATABASE=test;"_
& "UID=venu;PWD=venu; OPTION=3"
Set conn = ws.OpenConnection("test", dbDriverNoPrompt, False, str)
'Create table my_dao
Set queryDef = conn.CreateQueryDef("", "drop table if exists my_dao")
queryDef.Execute
Set queryDef = conn.CreateQueryDef("", "create table my_dao(Id INT AUTO_INCREMENT PRIMARY KEY, " _
& "Ts TIMESTAMP(14) Not NULL, Name varchar(20), Id2 INT)")
queryDef.Execute
'Insert new records using rs.addNew
Set rs = conn.OpenRecordset("my_dao")
Dim i As Integer
For i = 10 To 15
rs.AddNew
rs!Name = "insert record" & i
rs!Id2 = i
rs.Update
Next i
rs.Close
'rs update..
Set rs = conn.OpenRecordset("my_dao")
rs.Edit
rs!Name = "updated-string"
rs.Update
rs.Close
'fetch the table back...
Set rs = conn.OpenRecordset("my_dao", dbOpenDynamic)
str = "Results:"
rs.MoveFirst
While Not rs.EOF
str = " " & rs!Id & " , " & rs!Name & ", " & rs!Ts & ", " & rs!Id2
Debug.Print "DATA:" & str
rs.MoveNext
Wend
'rs Scrolling(레코드 이동)
rs.MoveFirst
str = " FIRST ROW: " & rs!Id & " , " & rs!Name & ", " & rs!Ts & ", " & rs!Id2
Debug.Print str
rs.MoveLast
str = " LAST ROW: " & rs!Id & " , " & rs!Name & ", " & rs!Ts & ", " & rs!Id2
Debug.Print str
rs.MovePrevious
str = " LAST-1 ROW: " & rs!Id & " , " & rs!Name & ", " & rs!Ts & ", " & rs!Id2
Debug.Print str
'free all resources
rs.Close
queryDef.Close
conn.Close
ws.Close

'*****************************************
' RDO사용하기
Dim rs As rdoResultset
Dim cn As New rdoConnection
Dim cl As rdoColumn
Dim SQL As String
'cn.Connect = "DSN=test;"
cn.Connect = "DRIVER={MySQL ODBC 3.51 Driver};"_
& "SERVER=localhost;"_
& " DATABASE=test;"_
& "UID=venu;PWD=venu; OPTION=3"
cn.CursorDriver = rdUseOdbc
cn.EstablishConnection rdDriverPrompt
'drop table my_rdo
SQL = "drop table if exists my_rdo"
cn.Execute SQL, rdExecDirect
'create table my_rdo
SQL = "create table my_rdo(id int, name varchar(20))"
cn.Execute SQL, rdExecDirect
'insert - direct
SQL = "insert into my_rdo values (100,'venu')"
cn.Execute SQL, rdExecDirect
SQL = "insert into my_rdo values (200,'MySQL')"
cn.Execute SQL, rdExecDirect
'rs insert
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.AddNew
rs!id = 300
rs!Name = "Insert1"
rs.Update
rs.Close
'rs insert
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.AddNew
rs!id = 400
rs!Name = "Insert 2"
rs.Update
rs.Close
'rs update
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
rs.Edit
rs!id = 999
rs!Name = "updated"
rs.Update
rs.Close
'fetch back...
SQL = "select * from my_rdo"
Set rs = cn.OpenResultset(SQL, rdOpenStatic, rdConcurRowVer, rdExecDirect)
Do Until rs.EOF
For Each cl In rs.rdoColumns
Debug.Print cl.Value,
Next
rs.MoveNext
Debug.Print
Loop
Debug.Print "Row count="; rs.RowCount
'close
rs.Close
cn.Close

좋아요! 싫어요!
twitter facebook me2day
95개(3/5페이지)
컴퓨터
번호 제목 글쓴이 조회 날짜
55 [컴퓨터] [vb60]쇼핑몰지원 원격 툴소스 첨부파일 8175 5425 2004.08.19 17:13
54 [컴퓨터] [ASP]새 교컴 위지윅게시판과 모양이 똑같은 ASP용소스 첨부파일 8175 7054 2004.08.05 23:05
53 [컴퓨터] WEB 3D입니다 구경오세요 김정식 5456 2004.02.11 19:46
52 [컴퓨터] 안녕하세요 컴퓨터교사모임이에요. 김미영 7108 2004.02.10 11:48
>> [컴퓨터] ASP나 VB에서 ADO,DAO,RDO를 위한 MySQL연결하기 8175 17473 2004.01.25 19:26
50 [컴퓨터] [html help workshop]물 간 건데 올려도 되나? 첨부파일 8175 5623 2003.12.30 22:46
49 [컴퓨터] 2002 전세계IP할당표 첨부파일 8175 5859 2003.12.02 14:49
48 [컴퓨터] 여러종류의 플래시을 CD및 웹으로 제작방법[강좌] 김용희 5336 2003.11.27 12:58
47 [컴퓨터] [vb60]작은 메신저 소스 첨부파일 8175 5523 2003.11.24 20:39
46 [컴퓨터] 오덕초등학교-동영상편집(10) 김용희 5400 2003.10.21 01:41
45 [컴퓨터] 오덕초등학교-프로듀셔 강좌(9) 김용희 4875 2003.10.18 09:58
44 [컴퓨터] 오덕초등학교 - 광고제작방법(8) 김용희 5446 2003.10.17 01:35
43 [컴퓨터] 오덕초등학교 - 동영상강좌(7) 김용희 5370 2003.10.15 09:42
42 [컴퓨터] 컴퓨터 청소 방법입니당 주영일 7962 2003.10.10 12:37
41 [컴퓨터] 오덕초등학교 - 동영상강좌(4) 김용희 5239 2003.10.09 23:58
40 [컴퓨터] 오덕초등학교-동영상강좌(3) 김용희 5194 2003.10.08 02:03
39 [컴퓨터] 오덕초등학교 - 동영상강좌(2) 김용희 4876 2003.10.07 02:14
38 [컴퓨터] 오덕초등학교 - 동영상강좌(1) 김용희 5397 2003.10.05 16:57
37 [컴퓨터] SnagIt을 이용한 영화 스틸 사진 만들기 첨부파일 김용희 5656 2003.10.01 19:29
36 [컴퓨터] Windows media player 9 [최신버젼으로 patch] 첨부파일 양석윤 5507 2003.09.07 00:43