void __fastcall TForm6::Button1Click(TObject *Sender)
{
int iIdx;
iIdx = StringGrid1->RowCount - 1;
StringGrid1->Cells[0][iIdx] = StrToInt(Edit1->Text);
StringGrid1->Cells[1][iIdx] = StrToInt(Edit2->Text);
Edit2->Text = ""; //清空“進貨數量”
StringGrid1->RowCount ++;//StringGrid增加一行
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
AnsiString sSQLSentence;
int i;
TQuery* Query1 = new TQuery(NULL);
Query1->DatabaseName = "dblib";
Query1->Close();
Query1->SQL->Clear();
sSQLSentence = "insert into 圖書借閱(讀者編號,圖書編號,借閱日期) values('"+StringGrid1->Cells[0][i] + "','"+StringGrid1->Cells[1][i] + "','" + DateTimePicker1->DateTime.DateString() + "')";
Query1->SQL->Add(sSQLSentence);
Query1->ExecSQL();
}
//---------------------------------------------------------------------------
哪里有問題嗎?運行時總是提示語法錯誤
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
你的表中,讀者編號和圖書編號是數值型的欄位吧?sSQLSentence = String().sprintf(
"insert into 圖書借閱(讀者編號,圖書編號,借閱日期) values(%s, %s, '%s')",
StringGrid1->Cells[0][i], StringGrid1->Cells[1][i],
DateTimePicker1->DateTime.DateString());
uj5u.com熱心網友回復:
這樣改了后,又顯示這個了
uj5u.com熱心網友回復:
話不多說, 請貼你的完整代碼uj5u.com熱心網友回復:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "borrownew.h"
#include <DBTables.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm6 *Form6;
//---------------------------------------------------------------------------
__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm6::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = caFree;
}
//---------------------------------------------------------------------------
void __fastcall TForm6::FormCreate(TObject *Sender)
{
StringGrid1->Cells[0][0] = "讀者編號";
StringGrid1->Cells[1][0] = "圖書編號";
DateTimePicker1->Date = Date();
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button1Click(TObject *Sender)
{
int iIdx;
iIdx = StringGrid1->RowCount - 1;
StringGrid1->Cells[0][iIdx] = StrToInt(Edit1->Text);
StringGrid1->Cells[1][iIdx] = StrToInt(Edit2->Text);
Edit2->Text = ""; //清空“進貨數量”
StringGrid1->RowCount ++;//StringGrid增加一行
}
//---------------------------------------------------------------------------
void __fastcall TForm6::Button2Click(TObject *Sender)
{
AnsiString sSQLSentence;
int i;
TQuery* Query1 = new TQuery(NULL);
Query1->DatabaseName = "dblib";
Query1->Close();
Query1->SQL->Clear();
sSQLSentence = String().sprintf("insert into 圖書借閱(讀者編號,圖書編號,借閱日期) values(%s, %s, '%s')",StringGrid1->Cells[0][i], StringGrid1->Cells[1][i], DateTimePicker1->DateTime.DateString());
//sSQLSentence = "insert into 圖書借閱(讀者編號,圖書編號,借閱日期) values('"+StringGrid1->Cells[0][i] + "','"+StringGrid1->Cells[1][i] + "','" + DateTimePicker1->DateTime.DateString() + "')");
Query1->ExecSQL();
}
//---------------------------------------------------------------------------
uj5u.com熱心網友回復:

想要實作的功能就是2樓那樣
uj5u.com熱心網友回復:
在你5樓的代碼中, i根本沒有賦值啊轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/143402.html
標籤:基礎類
上一篇:登錄系統
下一篇:型別轉化問題
