[VB] INSERT SQL 실행하기

VB 2015.05.15 09:00

■ INSERT SQL 실행하기

----------------------------------------------------------------------------------------------------

Dim pConnection     As ADODB.Connection

Dim pCommand        As ADODB.Command

Dim pParameter      As ADODB.Parameter

Dim nRecordAffected As Long

 

Set pConnection = GetMDBConnection("c:\test.mdb") ' "MDB 연결 구하기" 참조

 

If pConnection Is Nothing Then

 

    MsgBox "데이터베이스 파일 연결을 실패했습니다."

    

    Exit Sub

 

End If

 

Set pCommand = GetCommand(pConnection, adCmdText, True, "INSERT INTO Sample (ID, Name) VALUES (아이디, 명칭)") ' "명령 구하기" 참조

 

Set pParameter = AddParameter(pCommand, "아이디", adInteger, adParamInput, 2) ' "파라미터 추가하기" 참조

 

pParameter.Value = 4

 

Set pParameter = AddParameter(pCommand, "명칭", adVarChar, adParamInput, 50)

 

pParameter.Value = "라"

 

pCommand.Execute nRecordAffected

 

Print nRecordAffected

 

Set pCommand = Nothing

 

pConnection.Close

 

Set pConnection = Nothing

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker