unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Grids, DBGrids, DB, ADODB;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
ADOCommand1: TADOCommand;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//添加
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ADOCommand1.CommandText := 'INSERT INTO country VALUES("AAA", "BBB", "CCC", 111, 222)';
ADOCommand1.Execute;
ADOCommand1.CommandText :=
'INSERT INTO country(Name,Capital,Continent) VALUES("XXX", "YYY", "ZZZ")';
ADOCommand1.Execute;
except on E: Exception do
ShowMessage(E.Message);
end;
Button4.Click;
end;
//更新
procedure TForm1.Button2Click(Sender: TObject);
begin
ADOCommand1.CommandText := 'UPDATE country SET Area=123,Population=456 WHERE Name="AAA"';
ADOCommand1.Execute;
ADOCommand1.CommandText := 'UPDATE country SET Capital="MMM" WHERE Capital="YYY"';
ADOCommand1.Execute;
Button4.Click;
end;
//删除
procedure TForm1.Button3Click(Sender: TObject);
begin
ADOCommand1.CommandText := 'DELETE * From country WHERE Name="AAA"';
ADOCommand1.Execute;
ADOCommand1.CommandText := 'DELETE * From country WHERE Name="XXX"';
ADOCommand1.Execute;
Button4.Click;
end;
//查看
procedure TForm1.Button4Click(Sender: TObject);
begin
with ADODataSet1 do begin
Close;
CommandText := 'SELECT * FROM country';
Open;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
mdbFile: string;
begin
{因要修改数据库, 特复制了一份}
mdbFile := mdbFile + 'C:\Temp\dbdemos.mdb';
ADOConnection1.ConnectionString :=
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + mdbFile + ';Persist Security Info=False';
ADOConnection1.LoginPrompt := False;
ADOConnection1.Open; //ADOConnection1.Connected := True;
ADODataSet1.Connection := ADOConnection1;
ADOCommand1.Connection := ADOConnection1;
DBGrid1.DataSource := DataSource1;
DataSource1.DataSet := ADODataSet1;
end;
end.
学习 SQL 语句 - Insert、Update、Delete
原创JLee79 ©著作权
文章标签 SQL语句 数据库学习 文章分类 SQL Server 数据库
-
根据Excel生成Insert或Update语句
根据Excel生成SQL
EXCEL SQL -
【SQL注入】UPDATE、insert、delete注入
【SQL注入】
数据库 web安全 xml 数据 5e -
MyBatis insert、update、delete、sql 标签
配置属性如下: 属性 描述 id SQL编号,用于标识这条SQL parameterType STATEMENT、PREPARED(预编译)、CALLABLE(存储过程
mybatis insert insert标签用法 插入 sql标签 -
jpa 原生insert\delete\update\select语句
ueen/article
html .net JPA -
执行SQL语句---INSERT/UPDATE/DELETE
1、执行SQL语句函数: int mysql_query(MYSQL* mysql, const char * query); query:所有的sql语句2、例子: 向children表插入一条语句,查看sql语句改动的行数量。/* * MysqlQuery.c * * Created on: Sep 8, 2013 * Author: root */#include #include #include int main(){ MYSQL my_connection; int res; mysql_init(&my_connection); //if(my...
linux c/c++/Qt mysql #include sql语句