|
정말 매번 감사합니다..
질문을 자세하게 설명하라고 하셔서 아예 모두 올립니다..--;
먼저 DB파일은 Database DeskTop을 이용해서
[File]->[New]->[Table]->[Creat Table(Table type = Paradox7)] 순으로 해서 만들었습니다.
DB파일은 첨부했습니다.
소스코드..
[unit1.cpp]
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(Query1->Active) Query1->Close();
Query1->SQL->Clear();
Query1->SQL->Add("insert into aa.db");
Query1->SQL->Add("(Sn, Name)");
// 값이 전부 문자열 이라고 가정하고 한 것..
Query1->SQL->Add("Values");
Query1->SQL->Add("('" + Edit1->Text + "','" + Edit2->Text + "')");
Query1->ExecSQL();
Query1->Open();
}
//---------------------------------------------------------------------------
[unit1.h]
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <DB.hpp>
#include <DBTables.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
TQuery *Query1;
TEdit *Edit1;
TEdit *Edit2;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
코드는 이렇습니다.
저번에도 말씀드렸다싶이..
일단 한번은 데이터가 입력은 되는데요..
다음엔 경고창이 뜨면서 안되더라구요.
경고창내용..
(Project Project1.exe raised exception class EDBEngineError with message 'Key
violation.'. Process stopped. Use Step or Run to continue.)
왜 안되는지 참 막막하네요..--;
p.s 삽입말고 수정에시에는 또 다른 코드가 필요한가요?
아님 그냥 insert를 update를 바꾸면 되는 건가요?
책에서는 그리드에 출력한걸 수정할려면 UPdateSQL을 쓰라고 나오던데..
전 그냥 텍스트에서 정보 받아서 넣을꺼니깐 그거 쓸 필요가 없는 건가요?
|