以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助] Insert Into 返回ID (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=191509) |
-- 作者:建筑人生 -- 发布时间:2024/4/20 16:17:00 -- [求助] Insert Into 返回ID Dim cmd As New SQLCommand cmd.C cmd.CommandText = "Insert Into HeTong (gcmc,gcdz,htdw,htbh,xmfzr,htgq,kssj,htxs,htje,fpsl,wcsj,dwmc,dwdz,dwxz,lxr,lxdh1,lxdh2,email,zw,wx,qq,khmc,khzh,khh,swdjh,jlr,jlsj,fj) values (\'" & gcmc & "\',\'" & gcdz & "\',\'" & htdw & "\',\'" & htbh & "\',\'" & xmfzr & "\',\'" & htgq & "\',#" & kssj & "#,\'" & htxs & "\'," & htje & "," & fpsl & ",#" & wcsj & "#,\'" & dwmc & "\',\'" & dwdz & "\',\'" & dwxz & "\',\'" & lxr & "\',\'" & lxdh1 & "\',\'" & lxdh2 & "\',\'" & email & "\',\'" & zw & "\',\'" & wx & "\',\'" & qq & "\',\'" & khmc & "\',\'" & khzh & "\',\'" & khh & "\',\'" & swdjh & "\',\'" & jlr & "\',#" & jlsj & "#,\'" & fj & "\');Select SCOPE_IDENTITY()" Dim id As Integer = cmd.ExecuteScalar()\'新增行ID MessageBox.Show(ID) 加了黄色位置,提示在 SQL 语句结尾之后找到字符。,是Access外部数据库
|
-- 作者:有点蓝 -- 发布时间:2024/4/20 16:23:00 -- 这种用法仅支持SqlServer access只能是插入后,再另外使用能够唯一识别的列查询需要的行的主键。比如有一个编号列,每一行编号都不一样,可以 Dim cmd As New SQLCommand cmd.C cmd.CommandText = "Insert Into HeTong (g...... cmd.ExecuteNonQuery() cmd.CommandText = " select [_Identify] from HeTong where 某编号编号=\'xxxx\'" Dim id As Integer = cmd.ExecuteScalar()\'新增行ID |