Foxtable(狐表)用户栏目专家坐堂 → [求助] Insert Into 返回ID


  共有1387人关注过本帖树形打印复制链接

主题:[求助] Insert Into 返回ID

帅哥哟,离线,有人找我吗?
建筑人生
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:小狐 帖子:342 积分:3475 威望:0 精华:0 注册:2014/8/20 20:14:00
[求助] Insert Into 返回ID  发帖心情 Post By:2024/4/20 16:17:00 [只看该作者]


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外部数据库

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110553 积分:562655 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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



 回到顶部