//创建连接的方法
TADOConnection *Conn = new TADOConnection(NULL);
Conn->Provider = 数据库Provider的属性值;
Conn->ConnectionString = 连接字符串值;
Conn->LoginPrompt = false;
try
{
Conn->Connected = true;
}
catch(Exception &e)
{
//连接有错误, 错误信息为 e.Message
}
TADOQuery *Qy = new TADOQuery(NULL);
Qy->Connection = Conn; //就是前面创建的连接,或者用窗体里面的,例如 Qy->Connection = Form1->AdoConnection1;
Qy->SQL->Text = "select * from mytable";
try
{
//读出字段值
Qy->Active = true;
AnsiString s = qy->FieldByName("字段名")->AsString; //读出字段的值
//直接从查询结果里面修改字段值,并且储存到表里面
Qy->Edit();
Qy->FieldByName("字段名")->AsString = "字段值";
Qy->Post();
//下面用 update 语句修改表内容:
Qy->Active = false;
Qy->SQL->Text = "update mytable set 字段名='字段值' where 条件";
Qy->ExecSQL();
}
catch(Exception &e)
{
//执行有错误, 错误信息为 e.Message
}
delete Qy; //不用了的时候需要用 delete 释放占用的资源
delete Conn; //连接不用了的时候需要用 delete 释放占用的资源
--------------------next---------------------
阅读(1023) | 评论(0) | 转发(0) |