<small id='uNQVJ'></small><noframes id='uNQVJ'>

    <tfoot id='uNQVJ'></tfoot>
  • <i id='uNQVJ'><tr id='uNQVJ'><dt id='uNQVJ'><q id='uNQVJ'><span id='uNQVJ'><b id='uNQVJ'><form id='uNQVJ'><ins id='uNQVJ'></ins><ul id='uNQVJ'></ul><sub id='uNQVJ'></sub></form><legend id='uNQVJ'></legend><bdo id='uNQVJ'><pre id='uNQVJ'><center id='uNQVJ'></center></pre></bdo></b><th id='uNQVJ'></th></span></q></dt></tr></i><div id='uNQVJ'><tfoot id='uNQVJ'></tfoot><dl id='uNQVJ'><fieldset id='uNQVJ'></fieldset></dl></div>
      <bdo id='uNQVJ'></bdo><ul id='uNQVJ'></ul>

      1. <legend id='uNQVJ'><style id='uNQVJ'><dir id='uNQVJ'><q id='uNQVJ'></q></dir></style></legend>
      2. 在 asp.net 中插入后获取主键(visual basic)

        时间:2023-06-05
          <bdo id='LlS5Z'></bdo><ul id='LlS5Z'></ul>

          <small id='LlS5Z'></small><noframes id='LlS5Z'>

              • <legend id='LlS5Z'><style id='LlS5Z'><dir id='LlS5Z'><q id='LlS5Z'></q></dir></style></legend>

                1. <i id='LlS5Z'><tr id='LlS5Z'><dt id='LlS5Z'><q id='LlS5Z'><span id='LlS5Z'><b id='LlS5Z'><form id='LlS5Z'><ins id='LlS5Z'></ins><ul id='LlS5Z'></ul><sub id='LlS5Z'></sub></form><legend id='LlS5Z'></legend><bdo id='LlS5Z'><pre id='LlS5Z'><center id='LlS5Z'></center></pre></bdo></b><th id='LlS5Z'></th></span></q></dt></tr></i><div id='LlS5Z'><tfoot id='LlS5Z'></tfoot><dl id='LlS5Z'><fieldset id='LlS5Z'></fieldset></dl></div>
                    <tbody id='LlS5Z'></tbody>
                  <tfoot id='LlS5Z'></tfoot>

                  本文介绍了在 asp.net 中插入后获取主键(visual basic)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在添加这样的记录:

                  I'm adding a record like this:

                      Dim pathString As String = HttpContext.Current.Request.MapPath("Banking.mdb")
                      Dim odbconBanking As New OleDbConnection _
                               ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                               "Data Source=" + pathString)
                      Dim sql As String
                      sql = "INSERT INTO tblUsers ( FirstName, LastName, Address, City, Province, Zip, Phone, UserName, [Password])" & _
                                " VALUES ('" & firstName & "', '" & lastName & "', '" & address & _
                              "', '" & city & "', '" & province & "', '" & zip & "', '" & phone & "', '" & username & "', '" & password & "');"
                      odbconBanking.Open()
                      Dim cmd As New OleDbCommand(sql, odbconBanking)
                      cmd.ExecuteNonQuery()
                      odbconBanking.Close()
                  

                  主键是一个名为 UserID 的自动编号字段.那么,如何获取我刚刚插入的记录的主键呢?

                  The primary key is an autonumber field called UserID. So, how do I get the primary key of the record I just inserted?

                  谢谢.

                  推荐答案

                  我相信参数化查询应该是这样的:

                  I believe a parameterized query would look something like this:

                  Dim pathString As String = HttpContext.Current.Request.MapPath("Banking.mdb")
                  Dim odbconBanking As New OleDbConnection _
                       ("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                       "Data Source=" + pathString)
                  Dim sql As String
                  sql = "INSERT INTO tblUsers ( FirstName, LastName, Address, City, Province, Zip, Phone, UserName, [Password])" & _
                        " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
                  odbconBanking.Open()
                  Dim cmd As New OleDbCommand(sql, odbconBanking)
                  
                  //Add Params here
                  cmd.Parameters.Add(new OdbcParameter("@FirstName", firstName))
                  cmd.Parameters.Add(new OdbcParameter("@LastName", lastName))
                  //..etc
                  
                  //End add Params here
                  
                  cmd.ExecuteNonQuery()
                  Dim newcmd As New OleDbCommand("SELECT @@IDENTITY", odbconBanking)
                  uid = newcmd.ExecuteScalar
                  
                  odbconBanking.Close()
                  

                  我的语法可能有点偏离,因为我更习惯使用 Sql Server 库而不是 Odbc 库,但这应该可以帮助您入门.

                  My syntax might be a bit off as I am more accustomed to using the Sql Server library and not the Odbc library, but that should get you started.

                  这篇关于在 asp.net 中插入后获取主键(visual basic)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C# 将图片插入 Ms Access 下一篇:如何从excel导入documentDB中的批量数据?

                  相关文章

                  最新文章

                  <i id='vL2nV'><tr id='vL2nV'><dt id='vL2nV'><q id='vL2nV'><span id='vL2nV'><b id='vL2nV'><form id='vL2nV'><ins id='vL2nV'></ins><ul id='vL2nV'></ul><sub id='vL2nV'></sub></form><legend id='vL2nV'></legend><bdo id='vL2nV'><pre id='vL2nV'><center id='vL2nV'></center></pre></bdo></b><th id='vL2nV'></th></span></q></dt></tr></i><div id='vL2nV'><tfoot id='vL2nV'></tfoot><dl id='vL2nV'><fieldset id='vL2nV'></fieldset></dl></div>

                  1. <tfoot id='vL2nV'></tfoot>
                  2. <small id='vL2nV'></small><noframes id='vL2nV'>

                      <legend id='vL2nV'><style id='vL2nV'><dir id='vL2nV'><q id='vL2nV'></q></dir></style></legend>
                      • <bdo id='vL2nV'></bdo><ul id='vL2nV'></ul>