Home > Database > Mysql Tutorial > 用sql + Ado设置access的字段的默认值

用sql + Ado设置access的字段的默认值

WBOY
Release: 2016-06-07 15:43:21
Original
1226 people have browsed it

procedure TFormLOrder.ModifyDB; var F: Integer; begin with TADOQuery.Create( nil ) do try // ConnectionString := GetAdoAccConStr(SoftPath + SendDataDir +LogisOrderDB); Connection := ADOCon; SQL.Add( ' Select * from ' + tblogistics_orders);

<span>procedure</span><span> TFormLOrder.ModifyDB;
</span><span>var</span><span>
  F: Integer;
</span><span>begin</span>
  <span>with</span> TADOQuery.Create(<span>nil</span>) <span>do</span>
  <span>try</span>
<span>//</span><span>    ConnectionString := GetAdoAccConStr(SoftPath + SendDataDir +LogisOrderDB);</span>
    Connection :=<span> ADOCon;
    SQL.Add(</span><span>'</span><span>Select * from </span><span>'</span> +<span> tblogistics_orders); //不能用 Select seller_flag from ,否则会报 参数 seller_flag 没有默认值
    Open;
    </span><span>if</span> FieldList.Find(<span>'</span><span>seller_flag</span><span>'</span>) = <span>nil</span> <span>then //不能用 FieldByName,因为参数必须是存在的字段,否则会产生异常</span>
    <span>begin</span><span>
      Close;
      SQL.Clear;
      SQL.Add(</span><span>'</span><span>ALTER TABLE </span><span>'</span> +<span> tblogistics_orders);
      SQL.Add(</span><span>'</span><span>ADD COLUMN seller_flag INTEGER DEFAULT 0</span><span>'</span><span>);
</span><span>//</span><span>      ADOCon.Execute(sql.Text, F); //这个也可以的,并 不是 必须用这个</span>
<span>      ExecSQL;
    </span><span>end</span><span>;
    </span><span>//
</span><span>    Close;
    sql.Clear;
    sql.Add(</span><span>'</span><span>Select sub_tids from </span><span>'</span> +<span> tblogistics_orders);
    Open;
    </span><span>if</span> (FieldCount > <span>0</span>) <span>and</span> (FieldByName(<span>'</span><span>sub_tids</span><span>'</span>).Size 255) <span>then</span>
    <span>begin</span><span>
      Close;
      SQL.Clear;
      sql.Add(</span><span>'</span><span>ALTER TABLE </span><span>'</span> +<span> tblogistics_orders);
      SQL.Add(</span><span>'</span><span>ALTER COLUMN sub_tids TEXT(255)</span><span>'</span>); <span>//</span><span>换行的话,前面不用加 空格</span>
<span>      ExecSQL;
</span><span>//</span><span>      if RowsAffected > 0 then</span><span>
//</span><span>       ShowMessage('');</span>
    <span>end</span><span>;
  </span><span>finally</span><span>
    Free
  </span><span>end</span><span>;
</span><span>end</span>;
Copy after login

 

http://www.jb51.net/article/990.htm

 

http://m.blog.csdn.net/blog/xijupony/5741707

<span><span>[原]Access里的Alter Table
</span><span>2010</span>-<span>7</span>-<span>17</span><span>阅读1925 评论0

ASP连接ACCESS数据库通常有两种方法

</span><span>1</span>. "DRIVER=<span>{</span><span>Microsoft Access Driver (*.mdb)</span><span>}</span>;DBQ=<span>[数据库地址]"

</span><span>2</span>. "Provider=Microsoft.Jet.OLEDB.<span>4.0</span>;Data Source=<span>[数据库地址]"

第一种连接方式使用的是“ANSI SQL”,第二种为Microsoft Jet 数据库引擎。而Microsoft Jet 数据库引擎限制较少,例如,它允许在表达式中进行分组和排序,且提供了更强有力的表达式。诸如:CREATE TABLE、ALTER TABLE的在MS SQLSERVER数据库经常用到的更新数据表的SQL语句。

因此,推荐使用第二种数据连接方式。

以下是今天使用ALTER TABLE的一些心得。

语法:ALTER TABLE 表 ADD COLUMN 字段类型 [(字长)] [NOT NULL] [DEFAULT (VALUES)] [CONSTRAINT 索引] </span>|<span>

    ALTER COLUMN 字段类型 [(字长)] </span>|<span>

    CONSTRAINT 多重字段索引 } </span>|<span>

    DROP DROP</span><span>{</span><span>COLUMN 字段 I CONSTRAINT 索引名 </span><span>}</span><span> }

上面的语法资料出自《Microsoft Jet SQL 参考》,但其中并没有[DEFAULT (VALUES)]这一参数。经实验,DEFAULT设置默认值的参数完全是有效的。

但需要注意的是,NOT NULL</span>|NULL 不区分大小写。DEFAULT则区分,小写的"<span>default</span><span>"不是Jet SQL的关键字,并不起效。

附:《Microsoft Jet SQL 参考》,这是开发ACCESS的好帮助文档,值得推荐。</span></span>
Copy after login

 

http://linux.chinaunix.net/techdoc/database/2005/12/14/925763.shtml

 

http://www.cnblogs.com/luckboy/archive/2009/11/21/1607564.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template