求教:为啥 DBGrid 中没有显示
//---------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
//------------
Table1->Active = false;
Table1->DatabaseName = "newData";
Table1->TableType = ttFoxPro;
Table1->TableName = "new";
//--------------
//Table1->FieldDefs->Clear();
//Table1->FieldDefs->Add("SNO",ftInteger,0,false);
//Table1->FieldDefs->Add("Name",ftString,30,false);
//Table1->FieldDefs->Add("Add",ftString,50,false);
//Table1->FieldDefs->Add("Del",ftString,20,false);
Table1->FieldDefs->Clear();
TFieldDef* pdf;
pdf = Table1->FieldDefs->AddFieldDef();
pdf->Name = "SNO";
pdf->DataType = ftInteger;
pdf->Required = true;
pdf = Table1->FieldDefs->AddFieldDef();
pdf->Name = "Name";
pdf->DataType = ftString;
pdf->Size = 30;
/*
Table1->IndexDefs->Clear();
Table1->IndexDefs->Add("","Field1", TIndexOptions()<<ixPrimary <<ixUnique);
Table1->IndexDefs->Add("Fld2Index","Field2", TIndexOptions()<<ixCaseInsensitive);
*///----
try
{
Table1->CreateTable();
}catch(...)
{
ShowMessage("产生数据表失败");
}
}
先点击它 创建成功了
//---------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
static int iNum = 1;
Table1->Active = false;
Table1->DatabaseName = "newData";
Table1->TableType = ttFoxPro;
Table1->TableName = "new";
Table1->Open();
Table1->Append();
Table1->FieldByName("SNO")->AsInteger = iNum;
Table1->FieldByName("Name")->AsAnsiString = MsgSprintf("name%d",iNum);;
Table1->Post();
//Table1->First();
//Table1->Close();
iNum++;
Edit5->Text = Table1->RecordSize;
Edit3->Text = Table1->FieldDefs->Count;
Edit4->Text = Table1->FieldCount;
}
再点击它 貌是添加成功了
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Table1->Active = false;
Table1->DatabaseName = "newData";
Table1->TableType = ttFoxPro;
Table1->TableName = "new";
Table1->Open();
Table1->Edit();
Table1->FieldByName("SNO")->AsInteger = 2;
//Table1->FieldByName("Name")->AsAnsiString = "name";
Table1->Post();
//Table1->Close();
}
再点击它 貌是没发现错误,就是 DBGrid 中为啥无显示呢?
[解决办法]
DBGrid是否和DataSource帮定好了
[解决办法]
DataSource 绑定到Table了吗?
[解决办法]
首先去顶已经绑定了关系
然后确定Table是Open状态
最后确定table查询肯定有数据
[解决办法]
__fastcall 貌似是cbuild啊,不过cb里面可没有MsgSprintf。。。
不过要想在DbGrid里面显示表,必须设置其datasouce:
请确定一下:
是否添加了datasouse 及Dbgrid控件并设置其属性:
this->DataSource1->DataSet=Table1;
this->DBGrid1->DataSource=DataSource1;