Access有没有办法在插入数据的同时得到自动增长列的值
Access有没有办法在插入数据的同时得到自动增长列的值
在MS-SQLServer中可以这样:
INSERT INTO T_User (F_UserName,F_Age) OUTPUT INSERTED.id VALUES('于谦',37)
可是在ACCESS中好像不支持这样的语法吧?
没有,如果用ADO连接MDB,插入后,用select @@identity得到
string strsql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\\LkfTest.mdb;Persist Security Info=True";
using(OleDbConnection con = new OleDbConnection(strsql))
{
con.Open();
using (OleDbCommand cmd = con.CreateCommand())
{
cmd.CommandText = "INSERT INTO T_onlyone ( F_Onlyone )VALUES ('GDG');";
cmd.executenonquery();
cmd.CommandText = "SELECT @@IDENTITY";
textBox1.Text = (string)cmd.ExecuteScalar();
}
}