久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='OBM6o'></tfoot>

      <legend id='OBM6o'><style id='OBM6o'><dir id='OBM6o'><q id='OBM6o'></q></dir></style></legend>

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

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

          <bdo id='OBM6o'></bdo><ul id='OBM6o'></ul>

        使用 c# 從 SQL Server 插入命令返回值

        Return value from SQL Server Insert command using c#(使用 c# 從 SQL Server 插入命令返回值)

        • <legend id='oEhZD'><style id='oEhZD'><dir id='oEhZD'><q id='oEhZD'></q></dir></style></legend>
          <i id='oEhZD'><tr id='oEhZD'><dt id='oEhZD'><q id='oEhZD'><span id='oEhZD'><b id='oEhZD'><form id='oEhZD'><ins id='oEhZD'></ins><ul id='oEhZD'></ul><sub id='oEhZD'></sub></form><legend id='oEhZD'></legend><bdo id='oEhZD'><pre id='oEhZD'><center id='oEhZD'></center></pre></bdo></b><th id='oEhZD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oEhZD'><tfoot id='oEhZD'></tfoot><dl id='oEhZD'><fieldset id='oEhZD'></fieldset></dl></div>

              <tfoot id='oEhZD'></tfoot>

                <tbody id='oEhZD'></tbody>

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

                  <bdo id='oEhZD'></bdo><ul id='oEhZD'></ul>
                • 本文介紹了使用 c# 從 SQL Server 插入命令返回值的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

                  在 Visual Studio 中使用 C#,我將一行插入到這樣的表中:

                  Using C# in Visual Studio, I'm inserting a row into a table like this:

                  INSERT INTO foo (column_name)
                  VALUES ('bar')
                  

                  我想做這樣的事情,但我不知道正確的語法:

                  I want to do something like this, but I don't know the correct syntax:

                  INSERT INTO foo (column_name)
                  VALUES ('bar')
                  RETURNING foo_id
                  

                  這將從新插入的行返回 foo_id 列.

                  This would return the foo_id column from the newly inserted row.

                  此外,即使我找到了正確的語法,我還有另一個問題:我可以使用 SqlDataReaderSqlDataAdapter.據(jù)我所知,前者用于讀取數(shù)據(jù),后者用于操作數(shù)據(jù).在插入帶有 return 語句的行時,我既在操作又在讀取數(shù)據(jù),所以我不確定該使用什么.也許我應(yīng)該為此使用完全不同的東西?

                  Furthermore, even if I find the correct syntax for this, I have another problem: I have SqlDataReader and SqlDataAdapter at my disposal. As far as I know, the former is for reading data, the second is for manipulating data. When inserting a row with a return statement, I am both manipulating and reading data, so I'm not sure what to use. Maybe there's something entirely different I should use for this?

                  推薦答案

                  SCOPE_IDENTITY 返回插入到同一范圍內(nèi)的標(biāo)識列中的最后一個標(biāo)識值.范圍是一個模塊:存儲過程、觸發(fā)器、函數(shù)或批處理.因此,如果兩條語句在同一個存儲過程、函數(shù)或批處理中,則它們屬于同一范圍.

                  SCOPE_IDENTITY returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.

                  您可以使用 SqlCommand.ExecuteScalar 執(zhí)行插入命令并在一個查詢中檢索新 ID.

                  You can use SqlCommand.ExecuteScalar to execute the insert command and retrieve the new ID in one query.

                  using (var con = new SqlConnection(ConnectionString)) {
                      int newID;
                      var cmd = "INSERT INTO foo (column_name)VALUES (@Value);SELECT CAST(scope_identity() AS int)";
                      using (var insertCommand = new SqlCommand(cmd, con)) {
                          insertCommand.Parameters.AddWithValue("@Value", "bar");
                          con.Open();
                          newID = (int)insertCommand.ExecuteScalar();
                      }
                  }
                  

                  這篇關(guān)于使用 c# 從 SQL Server 插入命令返回值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  What are good algorithms for vehicle license plate detection?(車牌檢測有哪些好的算法?)
                  onClick event for Image in Unity(Unity中圖像的onClick事件)
                  Running Total C#(運(yùn)行總 C#)
                  Deleting a directory when clicked on a hyperlink with JAvascript.ASP.NET C#(單擊帶有 JAvascript.ASP.NET C# 的超鏈接時刪除目錄)
                  asp.net listview highlight row on click(asp.net listview 在單擊時突出顯示行)
                  Calling A Button OnClick from a function(從函數(shù)調(diào)用按鈕 OnClick)
                    <bdo id='8mA3G'></bdo><ul id='8mA3G'></ul>

                      <tbody id='8mA3G'></tbody>

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

                          <small id='8mA3G'></small><noframes id='8mA3G'>

                          <tfoot id='8mA3G'></tfoot>
                        1. <legend id='8mA3G'><style id='8mA3G'><dir id='8mA3G'><q id='8mA3G'></q></dir></style></legend>

                            主站蜘蛛池模板: 国产精品成人一区二区 | 国产一级在线 | 免费黄网站在线观看 | 日韩一区二区免费视频 | 国产黄色一级片 | 狠狠的干| 欧美.com| 国产日韩精品视频 | 日韩午夜一区二区三区 | 中文字幕 在线观看 | 九九热免费视频在线观看 | 五月激情婷婷六月 | 国产永久免费 | 日韩一级免费大片 | 美女国内精品自产拍在线播放 | 国产精品国产a | 二区中文字幕 | 视频二区 | 成人国产精品久久久 | 日本国产一区二区 | 一区二区三区视频免费观看 | 夜久久 | 黄色操视频 | 色噜噜亚洲男人的天堂 | 久久黄色精品视频 | 国产高清视频 | 亚洲免费三区 | 精品国产乱码久久久久久闺蜜 | 中文字幕在线播放第一页 | 色视频欧美 | 伊人免费视频二 | 亚洲 欧美 另类 综合 偷拍 | 久久久黑人 | 久久麻豆精品 | avav在线看| 在线观看国产精品一区二区 | 久久久久久高潮国产精品视 | 在线日韩 | 日韩免费看视频 | 欧美国产亚洲一区二区 | 久久综合入口 |