我觉的这不应该是个问题,以前想解决,没解决了,今天终于 下定决心,一定要解决。虽暂时用不着,也许以后用的着。其实很简单,在SQL Server里有个全局变量 @@IDENTITY,他用来记录当前链接产生的自动加1的值,这个变量在access里也可以用,呵呵,一家的产品嘛。
这个blog系统不能传附件,我想把他变成图像传上来,大家下载之后在变成rar扩展名,解压,这个方法行不同,看来之能贴代码了。
以下代码是在dotnet 2.0里写的,其他的编程语言也没关系:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
oleDbConnection1.Open();
}
private void button2_Click(object sender, EventArgs e)
{
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.CommandText = "insert into t1(aa) values('aa')";
oleDbCommand1.ExecuteNonQuery();
}
private void button3_Click(object sender, EventArgs e)
{
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.CommandText = "SELECT @@IDENTITY as ID_NEW;";
OleDbDataReader dr = oleDbCommand1.ExecuteReader();
if (dr.Read())
{
label1.Text = Convert.ToString((int)dr["ID_NEW"]);
}
else
{
label1.Text = "";
}
dr.Close();
}
private void button4_Click(object sender, EventArgs e)
{
oleDbConnection1.Close();
}
}
}
代码太简单,无需多说。
补充以下access自动编号的知识吧:
1、自动编号的数据类型是长整型。以下是说明:
Long(长整型)变量存储为 32 位(4 个字节)有符号的数值形式,其范围从 -2,147,483,648 到 2,147,483,647。Long 的类型声明字符为和号 (&)。
2、如果自动编号从1开始,一旦到达 2147483647 会自动跳转到-2147483648,然后继续缩小,一直到0。
3、如果再次到达了 1,如果你在设计表的时候定义了自动编号字段的“索引”属性为“有(无重复)”则系统会提示错误。如果没有设置,则自动编号继续从1开始增加
这个blog系统不能传附件,我想把他变成图像传上来,大家下载之后在变成rar扩展名,解压,这个方法行不同,看来之能贴代码了。
以下代码是在dotnet 2.0里写的,其他的编程语言也没关系:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
oleDbConnection1.Open();
}
private void button2_Click(object sender, EventArgs e)
{
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.CommandText = "insert into t1(aa) values('aa')";
oleDbCommand1.ExecuteNonQuery();
}
private void button3_Click(object sender, EventArgs e)
{
oleDbCommand1.CommandType = CommandType.Text;
oleDbCommand1.CommandText = "SELECT @@IDENTITY as ID_NEW;";
OleDbDataReader dr = oleDbCommand1.ExecuteReader();
if (dr.Read())
{
label1.Text = Convert.ToString((int)dr["ID_NEW"]);
}
else
{
label1.Text = "";
}
dr.Close();
}
private void button4_Click(object sender, EventArgs e)
{
oleDbConnection1.Close();
}
}
}
代码太简单,无需多说。
补充以下access自动编号的知识吧:
1、自动编号的数据类型是长整型。以下是说明:
Long(长整型)变量存储为 32 位(4 个字节)有符号的数值形式,其范围从 -2,147,483,648 到 2,147,483,647。Long 的类型声明字符为和号 (&)。
2、如果自动编号从1开始,一旦到达 2147483647 会自动跳转到-2147483648,然后继续缩小,一直到0。
3、如果再次到达了 1,如果你在设计表的时候定义了自动编号字段的“索引”属性为“有(无重复)”则系统会提示错误。如果没有设置,则自动编号继续从1开始增加