본문 바로가기

개발 Tip/Visual Basic

[VB.Net] PostgreSQL 데이터 입력하기

1. 신규 데이터 입력하기
        Dim intCount As Integer
 
        Try
            If DB_CONNECT() Then
                strCmd.Connection = gOleDBConn
                strCmd.CommandType = CommandType.Text
                strCmd.CommandText = "INSERT INTO person VALUES('" & cbRelate.Text.Substring(0, 2) & "', '" & txtName.Text & "', '" & txtBirthday.Text & "', '" & txtHomeAddr.Text & "', '" & txtHomeTel.Text & "', '" & txtComName.Text & "', '" & txtComAddr.Text & "', '" & txtComTel.Text & "', '" & txtCellPhone.Text & "', '" & txtMemo.Text & "')"
 
                objDA.InsertCommand = strCmd
                intCount = objDA.InsertCommand.ExecuteNonQuery()
 
                If intCount = -1 Then
                    MessageBox.Show("데이터 입력 성공", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    MessageBox.Show("데이터 입력 실패!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
 
                Call DB_DISCONNECT()
            Else
                MessageBox.Show("DB 연결을 확인하십시오!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
 
            Call DB_DISCONNECT()
        End Try